api

package
v0.0.0-...-b2761b6 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2014 License: GPL-3.0, GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package api has code that offers a REST API for the applications that want to push messages.

Index

Constants

View Source
const JSONMediaType = "application/json"
View Source
const MaxRequestBodyBytes = 4 * 1024

Variables

View Source
var (
	ErrNoContentLengthProvided = &APIError{
		http.StatusLengthRequired,
		invalidRequest,
		"A Content-Length must be provided",
	}
	ErrRequestBodyEmpty = &APIError{
		http.StatusBadRequest,
		invalidRequest,
		"Request body empty",
	}
	ErrRequestBodyTooLarge = &APIError{
		http.StatusRequestEntityTooLarge,
		invalidRequest,
		"Request body too large",
	}
	ErrWrongContentType = &APIError{
		http.StatusUnsupportedMediaType,
		invalidRequest,
		"Wrong content type, should be application/json",
	}
	ErrWrongRequestMethod = &APIError{
		http.StatusMethodNotAllowed,
		invalidRequest,
		"Wrong request method, should be POST",
	}
	ErrMalformedJSONObject = &APIError{
		http.StatusBadRequest,
		invalidRequest,
		"Malformed JSON Object",
	}
	ErrCouldNotReadBody = &APIError{
		http.StatusBadRequest,
		ioError,
		"Could not read request body",
	}
	ErrMissingData = &APIError{
		http.StatusBadRequest,
		invalidRequest,
		"Missing data field",
	}
	ErrUnknownChannel = &APIError{
		http.StatusBadRequest,
		unknownChannel,
		"Unknown channel",
	}
	ErrUnknown = &APIError{
		http.StatusInternalServerError,
		internalError,
		"Unknown error",
	}
	ErrCouldNotStoreNotification = &APIError{
		http.StatusServiceUnavailable,
		unavailable,
		"Could not store notification",
	}
)

Well-known prebuilt API errors

Functions

func MakeHandlersMux

func MakeHandlersMux(store store.PendingStore, broker broker.BrokerSending, logger logger.Logger) http.Handler

MakeHandlersMux makes a handler that dispatches for the various API endpoints.

func PanicTo500Handler

func PanicTo500Handler(h http.Handler, logger logger.Logger) http.Handler

PanicTo500Handler wraps another handler such that panics are recovered and 500 reported.

Types

type APIError

type APIError struct {
	// http status code
	StatusCode int `json:"-"`
	// machine readable label
	ErrorLabel string `json:"error"`
	// human message
	Message string `json:"message"`
}

APIError represents a API error (both internally and as JSON in a response).

func (*APIError) Error

func (apiErr *APIError) Error() string

type Broadcast

type Broadcast struct {
	Channel     string          `json:"channel"`
	ExpireAfter uint8           `json:"expire_after"`
	Data        json.RawMessage `json:"data"`
}

Broadcast request JSON object.

type BroadcastHandler

type BroadcastHandler state

func (*BroadcastHandler) ServeHTTP

func (h *BroadcastHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type Message

type Message struct {
	Registration string          `json:"registration"`
	CoalesceTag  string          `json:"coalesce_tag"`
	Data         json.RawMessage `json:"data"`
}

Jump to

Keyboard shortcuts

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