Compare commits
5 Commits
3c70ad2377
...
v0.12.14
Author | SHA1 | Date | |
---|---|---|---|
a0b561237a | |||
ad1e06229f | |||
e99a8dbcd6 | |||
d3513ae4fa | |||
99264c6715 |
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Server = (*event)(nil)
|
var _ Server = (*event)(nil)
|
||||||
@ -31,9 +32,8 @@ type msgChan struct {
|
|||||||
type event struct {
|
type event struct {
|
||||||
SessionList sync.Map
|
SessionList sync.Map
|
||||||
Count atomic.Int32
|
Count atomic.Int32
|
||||||
|
Register chan clientChan
|
||||||
Register chan clientChan
|
Unregister chan any
|
||||||
Unregister chan any
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() Server {
|
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("Connection", "keep-alive")
|
||||||
c.Writer.Header().Set("Transfer-Encoding", "chunked")
|
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 {
|
c.Stream(func(w io.Writer) bool {
|
||||||
if msg, ok := <-e; ok {
|
if msg, ok := <-e; ok {
|
||||||
c.SSEvent(msg.Name, msg.Message)
|
c.SSEvent(msg.Name, msg.Message)
|
||||||
|
Reference in New Issue
Block a user