aboutsummaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-11-26 21:22:31 +0700
committerShulhan <ms@kilabit.info>2023-11-26 21:32:52 +0700
commit5b7f3a702aa8210e9f3efcc9befeceb87755fc4d (patch)
tree476ba00f3464d2a6628b3b7397d5ea4247c785c7 /lib/http
parentbc06fe56976bc7b863dba65347d24d50359f903b (diff)
downloadpakakeh.go-5b7f3a702aa8210e9f3efcc9befeceb87755fc4d.tar.xz
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.
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/sseclient/event.go9
1 files changed, 9 insertions, 0 deletions
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 = ``