feat: use sse to fetch new messages (close #70)

This commit is contained in:
JustSong
2023-05-12 18:28:54 +08:00
parent 024fc97ced
commit 8f7e5456e5
6 changed files with 97 additions and 11 deletions

13
middleware/sse.go Normal file
View File

@@ -0,0 +1,13 @@
package middleware
import "github.com/gin-gonic/gin"
func SetSSEHeaders() func(c *gin.Context) {
return func(c *gin.Context) {
c.Writer.Header().Set("Content-Type", "text/event-stream")
c.Writer.Header().Set("Cache-Control", "no-cache")
c.Writer.Header().Set("Connection", "keep-alive")
c.Writer.Header().Set("Transfer-Encoding", "chunked")
c.Next()
}
}