Add files via upload

This commit is contained in:
公明 authored and GitHub committed 2026-03-29 01:22:17 +08:00
1 parent 628604fcae
commit c1a0d56769
5 files changed
+137 -22

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
package handler
import (
"fmt"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
// sseKeepalive sends periodic SSE comment lines so proxies (e.g. nginx proxy_read_timeout)
// and idle TCP paths do not close long-running streams when no data events are emitted for a while.
func sseKeepalive(c *gin.Context, stop <-chan struct{}) {
ticker := time.NewTicker(20 * time.Second)
defer ticker.Stop()
for {
select {
case <-stop:
return
case <-c.Request.Context().Done():
return
case <-ticker.C:
select {
case <-stop:
return
case <-c.Request.Context().Done():
return
default:
}
if _, err := fmt.Fprintf(c.Writer, ": keepalive\n\n"); err != nil {
return
}
if flusher, ok := c.Writer.(http.Flusher); ok {
flusher.Flush()
}
}
}
}