sseconn

package
v0.0.0-...-7bb8278 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientID

type ClientID [clientIDLength]byte

func ClientIDFromString

func ClientIDFromString(s string) (ClientID, error)

func NewClientID

func NewClientID() (ClientID, error)

func (ClientID) IsZero

func (c ClientID) IsZero() bool

func (ClientID) MarshalJSON

func (c ClientID) MarshalJSON() ([]byte, error)

func (ClientID) MarshalText

func (c ClientID) MarshalText() ([]byte, error)

func (ClientID) String

func (c ClientID) String() string

type ClientSecret

type ClientSecret [clientSecretLength]byte

func ClientSecretFromString

func ClientSecretFromString(s string) (ClientSecret, error)

func (ClientSecret) String

func (c ClientSecret) String() string

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is a HTTP handler that manages bidirectional connections on top of HTTP and SSE.

The client-to-server messages are sent over regular HTTP requests, and the server-to-client messages are dispatched via server sent events.

This handler handles two routes under a given prefix: 1. POST /prefix/command for client sent messages 2. GET /api/events/{ID} for server sent events

Connection steps: 1. Client sends initial POST to open connection with a client ID (how do we prevent takeovers?). 2. Server sends back SSE endpoint URL. 3. Client creates EventSource and when the connection is open, confirms to the server.

func NewHandler

func NewHandler(prefix string) *Handler

func (*Handler) Close

func (h *Handler) Close()

func (*Handler) Listen

func (h *Handler) Listen(clientID ClientID) (<-chan json.RawMessage, error)

func (*Handler) ListenConnections

func (h *Handler) ListenConnections() <-chan ClientID

func (*Handler) Send

func (h *Handler) Send(clientID ClientID, eventName string, payload interface{}) error

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL