[🚀] message

This commit is contained in:
bvbej 2024-09-07 15:55:14 +08:00
parent e99a8dbcd6
commit ad1e06229f

View File

@ -7,6 +7,7 @@ import (
"net/http"
"sync"
"sync/atomic"
"time"
)
var _ Server = (*event)(nil)
@ -122,6 +123,10 @@ func (stream *event) GinHandlerFunc(auth func(c *gin.Context) (string, error)) g
c.Writer.Header().Set("Connection", "keep-alive")
c.Writer.Header().Set("Transfer-Encoding", "chunked")
time.AfterFunc(time.Second, func() {
e <- msgChan{Name: "message", Message: "success"}
})
c.Stream(func(w io.Writer) bool {
if msg, ok := <-e; ok {
c.SSEvent(msg.Name, msg.Message)
@ -129,8 +134,6 @@ func (stream *event) GinHandlerFunc(auth func(c *gin.Context) (string, error)) g
}
return false
})
e <- msgChan{Name: "message", Message: "success"}
}
}