Documentation
¶
Index ¶
- Constants
- func HeartBeat(wait time.Duration, route Route) io.Closer
- type Client
- type Event
- func (receiver Event) Equal(that EventReader) bool
- func (receiver Event) EventData() string
- func (receiver Event) EventID() string
- func (receiver Event) EventName() string
- func (receiver *Event) Reset()
- func (receiver *Event) SetEventID(value string)
- func (receiver *Event) SetEventName(value string)
- func (receiver Event) String() string
- func (receiver *Event) Write(p []byte) (int, error)
- func (receiver Event) WriteTo(writer io.Writer) (n int64, err error)
- type EventReader
- type EventSetter
- type EventWriter
- type Route
Constants ¶
const ContentType string = "text/event-stream"
Variables ¶
This section is empty.
Functions ¶
func HeartBeat ¶
HeatBeat sends a heartbeat comment to the 'route' evey 'wait' duration of time.
You want to use this to make sure the HTTP connection does NOT get closed due to inactivity.
You should almost always use this.
Example usage:
func ServeHTTP(resp http.ResponseWriter, req *http.Request) { // ... var route httpsse.Route = httpsse.NewRoute() httpsse.HeatBeat(4 * time.Second, route) // ... route.ServeHTTP(resp, req) }
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
An event represents an HTTP server-sent event.
func (Event) Equal ¶
func (receiver Event) Equal(that EventReader) bool
Equal returns whether two events are equal.
Two events arer equal if their event-data, event-id, and event-name are all equal.
func (Event) EventData ¶
EventID returns the event-ID
For example, if this is the event:
event: banana id: yellow-123 data: once data: twice data: thirce data: fource
Then EventID would return:
"once\ntwice\nthrice\nfource"
func (Event) EventID ¶
EventID returns the event-ID.
For example, if this is the event:
event: banana id: yellow-123 data: once data: twice data: thirce data: fource
Then EventID would return:
"yellow-123"
func (Event) EventName ¶
EventName returns the event-name.
For example, if this is the event:
event: banana id: yellow-123 data: once data: twice data: thirce data: fource
Then EventName would return:
"banana"
func (*Event) SetEventID ¶
SetEventID sets the event-ID.
func (*Event) SetEventName ¶
SetEventName sets the event-name.
func (Event) String ¶
String returns the serialize form of the event, as defined by the HTTP-SSE specification: https://html.spec.whatwg.org/multipage/server-sent-events.html
So, for example, if event-ID is:
"yellow-123"
And, for example. event-name is"
"banana"
And the event-data is:
"once\ntwice\nthrice\nfource"
Then this would return:
": {\n"+ "event: banana\n" + "id: yello123\n" + "data: once\n" + "data: twice\n" + "data: thice\n" + "data: fource\n" + ": }\n"+ "\n"
func (Event) WriteTo ¶
WriteTo writers the serialized form of the event, as defined by the HTTP-SSE specification: https://html.spec.whatwg.org/multipage/server-sent-events.html
So, for example, if event-ID is:
"yellow-123"
And, for example. event-name is"
"banana"
And the event-data is:
"once\ntwice\nthrice\nfource"
Then this would write:
": {\n"+ "event: banana\n" + "id: yello123\n" + "data: once\n" + "data: twice\n" + "data: thice\n" + "data: fource\n" + ": }\n"+ "\n"
type EventReader ¶
type EventSetter ¶
EventSetter represents an event that can be written to.
Use Write to write the event-data.
Use SetEventName to set the event-name.
Use SetEventID to set the event-ID.
You can give anything that is an EventSetter to Client.Decode
Event is an EventSetter, and can be passed to Client.Decode
But you can also use other types, including creating your own, that are EventSetter, and pass it to Client.Decode