-
Notifications
You must be signed in to change notification settings - Fork 0
/
sse.go
29 lines (23 loc) · 964 Bytes
/
sse.go
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
26
27
28
29
package sse
import (
"time"
"github.com/justinjudd/competition-example/sse/broker"
"github.com/justinjudd/competition-example/sse/event"
)
type (
// The Config type contains configuration variables for the SSE broker.
Config struct {
Timeout time.Duration // Determines how long the broker will wait to write to a client.
Tolerance int // Determines how many sequential errors a client can have until they are forcefully disconnected.
ErrorHandler broker.ErrorHandler // Defines a custom HTTP error handling method to use when controller errors occur.
}
)
// NewBroker creates a new instance of the SSE broker using the given configuration.
func NewBroker(cnf Config) broker.Broker {
broker := broker.New(cnf.Timeout, cnf.Tolerance, cnf.ErrorHandler)
return broker
}
// NewEvent creates a new event that can be broadcast to clients.
func NewEvent(t string, data []byte) *event.Event {
return event.New(t, data)
}