Skip to content
Node: express, cors, helmet, morgangithub.com/sahilkhaire/gox/http

EventStream.SSE

Overview

SSE prepares the response for server-sent events.

Part of the http package — Node.js analog: express, cors, helmet, morgan.

Method on EventStream — call it on a value of that type after constructing or receiving one from a constructor.

Signature

go
func SSE(c *Ctx) (*EventStream, error)

Compare: Node.js · Standard Go · gox

js
// Typical express, cors, helmet, morgan pattern in Node.js
go
func handler(w http.ResponseWriter, r *http.Request) {
    // chi or net/http
}
go
import "github.com/sahilkhaire/gox/http"

stream, err := http.SSE(w, r)

Example

go
import "github.com/sahilkhaire/gox/http"

stream, err := http.SSE(w, r)

Tips

Stack Logger, Recover, and Security middleware the way you would morgan + helmet in Express.

Standard library alternative

Use the standard library directly:

go
func handler(w http.ResponseWriter, r *http.Request) {
    // chi or net/http
}

Back to http package overview

MIT Licensed · Built for Node.js developers moving to Go