Repository navigation
Releases: thomas-osgood/ssehandler
Releases · thomas-osgood/ssehandler
Release list
v1.2.0
What's Changed
- feat(cors): Header Options by @thomas-osgood in #18
Full Changelog: v1.1.0...v1.2.0
Added more CORS header options for SSEHandler.
v1.1.0
What's Changed
- fix(endpoint): Optimizations by @thomas-osgood in #16
Full Changelog: v1.0.2...v1.1.0
Optimizations.
- Added mutex for synchronization safety.
- Updated UUID generation logic.
- Buffered comms channel.
v1.0.2
Overview
SSEChannelMap now uses the github.com/google/uuid library to generate UUID keys.
New:
type SSEChannelMap map[uuid.UUID]SSEChannelOld:
type SSEChannelMap map[string]SSEChannelAssociated Issues
#5 : Use UUID
v1.0.1
Overview
Added a new ID field to the SSEMessage struct and added JSON and XML tags to the SSEMessage fields.
SSEMessage
type SSEMessage struct {
// name of the event that will be transmitted.
Event string `json:"event" xml:"event"`
// id assigned to the event type. (optional)
Id string `json:"id" xml:"id"`
// data to be transmitted to the client.
//
// for best results, this should be a JSON object.
Data string `json:"data" xml:"data"`
}Associated Issues
v1.0.0
Description
Initial release of the SSE Handler library.
This handler will add clients to the client map when they connect and remove them when they disconnect. This will automatically create a channel for each client that connects, allowing the function feeding the channels to focus on generating the information and now worry about the channel management.
Basic SSE functionality and endpoint function are included within this release.
// most likely a global variable ...
clientMap := make(ssehandler.SSEChannelMap)
// other code
hdl, err := ssehandler.NewSSEHandler(ssehandler.WithClientMap(clientMap))
if err != nil {
// handle error
}
http.HandleFunc("/sse", hdl.EndpointFunc)
// other code// in "worker function"
eventtype = "message"
payload, err = json.Marshal(data)
if err != nil {
// handle error
}
// this will transmit the data to all clients in the client map.
for _, curchan := range clientMap {
curchan <- ssehandler.SSEMessage{Data: string(payload), Event: eventtype}
}