Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
slhmy committed Oct 4, 2023
1 parent 3075bd9 commit f64d9c1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions application/server/handler/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ func Stream(ginCtx *gin.Context) {

counter := 0
ginCtx.Stream(func(w io.Writer) bool {
// With event type
message := fmt.Sprintf("event: %s\ndata: %s\n\n", "eventType", time.Now().String())
logrus.Infof("Send message:\n%s", message)
fmt.Fprint(w, message)
time.Sleep(1 * time.Second)
counter++
if counter > 5 {
// Close connection (without event type)
closeMessage := fmt.Sprintf("data: %s\n\n", "close")
fmt.Fprint(w, closeMessage)
return false
Expand Down

0 comments on commit f64d9c1

Please sign in to comment.