package sse import ( "fmt" "github.com/gin-gonic/gin" "testing" "time" ) func TestSSE(t *testing.T) { router := gin.Default() stream := NewServer() user := "18926340" go func() { for { time.Sleep(time.Second * 3) now := time.Now().Format("2006-01-02 15:04:05") currentTime := fmt.Sprintf("The Current Time Is %v", now) stream.Push(user, "message", currentTime) } }() router.GET("/stream", stream.HandlerFunc(func(c *gin.Context) (string, error) { return user, nil })) router.StaticFile("/", "./client.html") _ = router.Run(":8085") }