Documentation ¶
Overview ¶
This package contains the Server Sent Events implementation used by horizon.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // known errors ErrRateLimited = errors.New("Rate limit exceeded") )
Functions ¶
func WriteEvent ¶
func WriteEvent(ctx context.Context, w http.ResponseWriter, e Event)
WriteEvent does the actual work of formatting an SSE compliant message sending it over the provided ResponseWriter and flushing.
func WritePreamble ¶
func WritePreamble(ctx context.Context, w http.ResponseWriter) bool
WritePreamble prepares this http connection for streaming using Server Sent Events. It sends the initial http response with the appropriate headers to do so.
Types ¶
type Eventable ¶
type Eventable interface { // SseEvent returns the SSE compatible form of the implementer SseEvent() Event }
Eventable represents an object that can be converted to an SSE compatible event.
type GenerateEventsFunc ¶
GenerateEventsFunc generates a slice of sse.Event which are sent via streaming.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func NewStream ¶
func NewStream(ctx context.Context, w http.ResponseWriter) *Stream
NewStream creates a new stream against the provided response writer.
func (*Stream) Init ¶
func (s *Stream) Init()
Init function is only executed once. It writes the preamble event which includes the HTTP response code and a hello message. This should be called before any method that writes to the client to ensure that the preamble has been sent first.
type StreamHandler ¶
StreamHandler represents a stream handling action
func (StreamHandler) ServeStream ¶
func (handler StreamHandler) ServeStream( w http.ResponseWriter, r *http.Request, limit int, generateEvents GenerateEventsFunc, )
ServeStream handles a SSE requests, sending data every time there is a new ledger.