sse-cluster: Index | Files

package handler

import ""

Package handler contains types for interacting with the broker implementation via HTTP.


Package Files

handler.go middleware.go

func CORSMiddleware Uses

func CORSMiddleware(next http.Handler) http.Handler

CORSMiddleware is an HTTP middleware that adds cross-origin headers to the HTTP response writer.

type Broker Uses

type Broker interface {
    Status() *broker.Status
    Publish(string, string, broker.Message) error
    NewClient(string, string) (*broker.Client, error)
    RemoveClient(string, string)

The Broker interface defines methods the HTTP handlers use to perform operations against the broker from HTTP requests.

type Handler Uses

type Handler struct {
    // contains filtered or unexported fields

The Handler type contains methods for handling inbound HTTP requests to the broker.

func New Uses

func New(br Broker) *Handler

New creates a new instance of the Handler type with the given broker

func (*Handler) Publish Uses

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

Publish handles an incoming HTTP POST request and writes a message to the broker. Returns a 400 if invalid JSON has been provided.

func (*Handler) Status Uses

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

Status handles an incoming HTTP GET request that returns the current status of the node and the gossip member list

func (*Handler) Subscribe Uses

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

Subscribe handles an incoming HTTP GET request and starts an event-stream with the client. The connection remains open while events are read from the broker. Events are written sequentially in 'text/event-stream' format. When the client disconnects, they're removed from the broker.

Package handler imports 6 packages (graph) and is imported by 1 packages. Updated 2019-05-09. Refresh now. Tools for package owners.