Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0b561237a | |||
ad1e06229f | |||
e99a8dbcd6 | |||
d3513ae4fa | |||
99264c6715 |
@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ Server = (*event)(nil)
|
||||
@ -31,9 +32,8 @@ type msgChan struct {
|
||||
type event struct {
|
||||
SessionList sync.Map
|
||||
Count atomic.Int32
|
||||
|
||||
Register chan clientChan
|
||||
Unregister chan any
|
||||
Register chan clientChan
|
||||
Unregister chan any
|
||||
}
|
||||
|
||||
func NewServer() Server {
|
||||
@ -123,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)
|
||||
|
Reference in New Issue
Block a user