本文整理匯總了Golang中github.com/gin-gonic/gin.Context.SSEvent方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.SSEvent方法的具體用法?Golang Context.SSEvent怎麽用?Golang Context.SSEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Context
的用法示例。
在下文中一共展示了Context.SSEvent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: timeStream
func (app *appContext) timeStream(c *gin.Context) {
recv := app.timeGroup.Join()
defer recv.Close()
c.Stream(func(w io.Writer) bool {
c.SSEvent("message", recv.Recv().(string))
return true
})
}
示例2: stream
func stream(c *gin.Context) {
roomid := c.Param("roomid")
listener := openListener(roomid)
defer closeListener(roomid, listener)
c.Stream(func(w io.Writer) bool {
c.SSEvent("message", <-listener)
return true
})
}
示例3: stream
func stream(ctx *gin.Context) {
ticker := time.NewTicker(500 * time.Millisecond)
defer func() {
ticker.Stop()
}()
ctx.Stream(func(w io.Writer) bool {
select {
case tm := <-ticker.C:
ctx.SSEvent("", tm)
}
return true
})
}
示例4: streamRoom
func streamRoom(c *gin.Context) {
roomid := c.Param("roomid")
listener := openListener(roomid)
ticker := time.NewTicker(1 * time.Second)
users.Add("connected", 1)
defer func() {
closeListener(roomid, listener)
ticker.Stop()
users.Add("disconnected", 1)
}()
c.Stream(func(w io.Writer) bool {
select {
case msg := <-listener:
messages.Add("outbound", 1)
c.SSEvent("message", msg)
case <-ticker.C:
c.SSEvent("stats", Stats())
}
return true
})
}