handler

package
v0.0.0-...-525d4e8 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(next http.Handler) http.Handler

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

Types

type Broker

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

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

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

func New

func New(br Broker) *Handler

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

func (*Handler) Publish

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

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

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.

Jump to

Keyboard shortcuts

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