From 5b7f3a702aa8210e9f3efcc9befeceb87755fc4d Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 26 Nov 2023 21:22:31 +0700 Subject: http/sseclient: add method IDInt to Event The IDInt return the ID as int64. If the ID cannot be converted to integer it would return 0. --- lib/http/sseclient/event.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/http/sseclient/event.go b/lib/http/sseclient/event.go index d191cf32..b4ceeba2 100644 --- a/lib/http/sseclient/event.go +++ b/lib/http/sseclient/event.go @@ -4,6 +4,8 @@ package sseclient +import "strconv" + // List of system event type. const ( // EventTypeOpen is set when connection succesfully established. @@ -24,6 +26,13 @@ type Event struct { ID string } +// IDInt return the ID as int64. +// If the ID cannot be converted to integer it would return 0. +func (ev *Event) IDInt() (id int64) { + id, _ = strconv.ParseInt(ev.ID, 10, 64) + return id +} + func (ev *Event) reset(id string) { ev.Type = EventTypeMessage ev.Data = `` -- cgit v1.3