package sseclient
import "git.sr.ht/~shulhan/pakakeh.go/lib/http/sseclient"
Package sseclient implement HTTP client for Server-Sent Events (SSE).
Notes on implementation
The SSE specification have inconsistent state when dispatching empty data. In the "9.2.6 Interpreting an event stream", if the data buffer is empty it would return; but in the third example it can dispatch an empty string. In this implement we ignore an empty string in server and client.
References,
Index ¶
Constants ¶
const ( // EventTypeOpen is set when connection succesfully established. // The passed [Event.Data] is empty. EventTypeOpen = `open` // EventTypeMessage is set when client received message from server, // possibly with new ID. EventTypeMessage = `message` EventTypeError = `error` )
List of system event type.
Types ¶
type Client ¶
type Client struct { C <-chan Event // Endpoint define the HTTP server URL to connect. Endpoint string // LastEventID define the last event ID to be sent during handshake. // Once the handshake success, this field will be reset and may set // with next ID from server. // This field is optional. LastEventID string // Timeout define the read and write timeout when reading and // writing from/to server. // This field is optional default to 10 seconds. Timeout time.Duration // Retry define how long, in milliseconds, the client should wait // before reconnecting back to server after disconnect. // Zero or negative value disable it. // // This field is optional, default to 0 (not retrying). Retry time.Duration // Insecure allow connect to HTTPS endpoint with invalid // certificate. Insecure bool // contains filtered or unexported fields }
Client for SSE. Once the Client filled, user need only to call Connect to start receiving message from channel C.
func (*Client) Close ¶
Close the connection and release all resources.
func (*Client) Connect ¶
Connect to server and start consume the message and propagate to each registered handlers.
The header parameter define custom, optional HTTP header to be sent during handshake. The following header cannot be set: Host, User-Agent, and Accept.
type Event ¶
Event contains SSE message from server or client status.
func (*Event) IDInt ¶
IDInt return the ID as int64. If the ID cannot be converted to integer it would return 0.
Source Files ¶
- Version
- v0.60.0 (latest)
- Published
- Feb 1, 2025
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 11 minutes ago –
Tools for package owners.