File: interface.go

package info (click to toggle)
golang-github-donovanhide-eventsource 0.0~git20210830.c590279-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, experimental, forky, sid, trixie
  • size: 132 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 1,181 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Package eventsource implements a client and server to allow streaming data one-way over a HTTP connection
// using the Server-Sent Events API http://dev.w3.org/html5/eventsource/
//
// The client and server respect the Last-Event-ID header.
// If the Repository interface is implemented on the server, events can be replayed in case of a network disconnection.
package eventsource

// Any event received by the client or sent by the server will implement this interface
type Event interface {
	// Id is an identifier that can be used to allow a client to replay
	// missed Events by returning the Last-Event-Id header.
	// Return empty string if not required.
	Id() string
	// The name of the event. Return empty string if not required.
	Event() string
	// The payload of the event.
	Data() string
}

// If history is required, this interface will allow clients to reply previous events through the server.
// Both methods can be called from different goroutines concurrently, so you must make sure they are go-routine safe.
type Repository interface {
	// Gets the Events which should follow on from the specified channel and event id.
	Replay(channel, id string) chan Event
}