You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to implement SSE-Event endpoint using strict-server: true as configuration?
I do not have straight access to gin.Context so I'm not able to write easy sse-event implementation like this:
engine.Handle("GET", "/render/event", 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")
// Here, we would typically listen to a channel that receives updates about render tasks
for {
// Check if the client is still connected
if cn, ok := c.Writer.(http.CloseNotifier); ok {
select {
case <-cn.CloseNotify():
fmt.Println("Client has disconnected.")
return
default:
// Here you would have logic that checks for updates from the render process
// For demonstration, we're just sending the current time every 5 seconds
fmt.Fprintf(c.Writer, "data: Render update at %v\n\n", time.Now())
c.Writer.Flush()
}
}
time.Sleep(5 * time.Second)
}
})
get:
summary: Subscribe to render updates
description: |
Establishes a stream connection to receive real-time updates about rendering tasks via Server-Sent Events (SSE).
operationId: renderEvent
responses:
'200':
description: |
A continuous stream of server-sent events.
content:
text/event-stream:
schema:
type: string
example: |
data: Render update at 2023-03-29T12:34:56Z
headers:
Cache-Control:
schema:
type: string
description: No caching is allowed for this stream.
Connection:
schema:
type: string
description: Advises the client to keep the connection open.
Content-Type:
schema:
type: string
description: The MIME type of this stream is text/event-stream.
default:
$ref: "../responses/UnexpectedError.yaml"
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
Is it possible to implement SSE-Event endpoint using strict-server: true as configuration?
I do not have straight access to gin.Context so I'm not able to write easy sse-event implementation like this:
My configuration:
My function to implement:
Beta Was this translation helpful? Give feedback.
All reactions