Documentation

Index

Constants

View Source
const CodeBadGateway = "M_BAD_GATEWAY" // 502
View Source
const CodeBadRequest = "M_BAD_REQUEST" // 400

Standard Errors in Matrix errcode format.

View Source
const CodeConflict = "M_CONFLICT" // 409
View Source
const CodeExpectationFailed = "M_EXPECTATION_FAILED" // 417
View Source
const CodeFailedDependency = "M_FAILED_DEPENDENCY" // 424
View Source
const CodeForbidden = "M_FORBIDDEN" // 403
View Source
const CodeGatewayTimeout = "M_GATEWAY_TIMEOUT" // 504
View Source
const CodeGone = "M_GONE" // 410
View Source
const CodeHTTPVersionNotSupported = "M_HTTP_VERSION_NOT_SUPPORTED" // 505
View Source
const CodeInsufficientStorage = "M_INSUFFICIENT_STORAGE" // 507
View Source
const CodeInternalServerError = "M_INTERNAL_SERVER_ERROR" // 500
View Source
const CodeLengthRequired = "M_LENGTH_REQUIRED" // 411
View Source
const CodeLocked = "M_LOCKED" // 423
View Source
const CodeLoopDetected = "M_LOOP_DETECTED" // 508
View Source
const CodeMethodNotAllowed = "M_METHOD_NOT_ALLOWED" // 405
View Source
const CodeMisdirectedRequest = "M_MISDIRECTED_REQUEST" // 421
View Source
const CodeNetworkAuthenticationRequired = "M_NETWORK_AUTHENTICATION_REQUIRED" // 511
View Source
const CodeNotAcceptable = "M_NOT_ACCEPTABLE" // 406
View Source
const CodeNotExtended = "M_NOT_EXTENDED" // 510
View Source
const CodeNotFound = "M_NOT_FOUND" // 404
View Source
const CodeNotImplemented = "M_NOT_IMPLEMENTED" // 501
View Source
const CodePaymentRequired = "M_PAYMENT_REQUIRED" // 402
View Source
const CodePreconditionFailed = "M_PRECONDITION_FAILED" // 412
View Source
const CodePreconditionRequired = "M_PRECONDITION_REQUIRED" // 428
View Source
const CodeProxyAuthRequired = "M_PROXY_AUTH_REQUIRED" // 407
View Source
const CodeRequestEntityTooLarge = "M_REQUEST_ENTITY_TOO_LARGE" // 413
View Source
const CodeRequestHeaderFieldsTooLarge = "M_REQUEST_HEADER_FIELDS_TOO_LARGE" // 431
View Source
const CodeRequestTimeout = "M_REQUEST_TIMEOUT" // 408
View Source
const CodeRequestURITooLong = "M_REQUEST_URI_TOO_LONG" // 414
View Source
const CodeRequestedRangeNotSatisfiable = "M_REQUESTED_RANGE_NOT_SATISFIABLE" // 416
View Source
const CodeServiceUnavailable = "M_SERVICE_UNAVAILABLE" // 503
View Source
const CodeTeapot = "M_TEAPOT" // 418
View Source
const CodeTooEarly = "M_TOO_EARLY" // 425
View Source
const CodeTooManyRequests = "M_TOO_MANY_REQUESTS" // 429
View Source
const CodeUnauthorized = "M_UNAUTHORIZED" // 401
View Source
const CodeUnavailableForLegalReasons = "M_UNAVAILABLE_FOR_LEGAL_REASONS" // 451
View Source
const CodeUnprocessableEntity = "M_UNPROCESSABLE_ENTITY" // 422
View Source
const CodeUnsupportedMediaType = "M_UNSUPPORTED_MEDIA_TYPE" // 415
View Source
const CodeUpgradeRequired = "M_UPGRADE_REQUIRED" // 426
View Source
const CodeVariantAlsoNegotiates = "M_VARIANT_ALSO_NEGOTIATES" // 506

Variables

View Source
var ErrorBadGateway = NewHALError("Bad Gateway", CodeBadGateway)
View Source
var ErrorBadRequest = NewHALError("Bad Request", CodeBadRequest)

Error* are net/http status codes to Error objects.

View Source
var ErrorConflict = NewHALError("Conflict", CodeConflict)
View Source
var ErrorExpectationFailed = NewHALError("Expectation Failed", CodeExpectationFailed)
View Source
var ErrorFailedDependency = NewHALError("Failed Dependency", CodeFailedDependency)
View Source
var ErrorForbidden = NewHALError("Forbidden", CodeForbidden)
View Source
var ErrorGatewayTimeout = NewHALError("Gateway Timeout", CodeGatewayTimeout)
View Source
var ErrorGone = NewHALError("Gone", CodeGone)
View Source
var ErrorHTTPVersionNotSupported = NewHALError("HTTP Version Not Supported", CodeHTTPVersionNotSupported)
View Source
var ErrorInsufficientStorage = NewHALError("Insufficient Storage", CodeInsufficientStorage)
View Source
var ErrorInternalServerError = NewHALError("Internal Server Error", CodeInternalServerError)
View Source
var ErrorLengthRequired = NewHALError("Length Required", CodeLengthRequired)
View Source
var ErrorLocked = NewHALError("Locked", CodeLocked)
View Source
var ErrorLoopDetected = NewHALError("Loop Detected", CodeLoopDetected)
View Source
var ErrorMethodNotAllowed = NewHALError("Method Not Allowed", CodeMethodNotAllowed)
View Source
var ErrorMisdirectedRequest = NewHALError("Misdirected Request", CodeMisdirectedRequest)
View Source
var ErrorNetworkAuthenticationRequired = NewHALError("Network Authentication Required", CodeNetworkAuthenticationRequired)
View Source
var ErrorNotAcceptable = NewHALError("Not Acceptable", CodeNotAcceptable)
View Source
var ErrorNotExtended = NewHALError("Not Extended", CodeNotExtended)
View Source
var ErrorNotFound = NewHALError("Not Found", CodeNotFound)
View Source
var ErrorNotImplemented = NewHALError("Not Implemented", CodeNotImplemented)
View Source
var ErrorPaymentRequired = NewHALError("Payment Required", CodePaymentRequired)
View Source
var ErrorPreconditionFailed = NewHALError("Precondition Failed", CodePreconditionFailed)
View Source
var ErrorPreconditionRequired = NewHALError("Precondition Required", CodePreconditionRequired)
View Source
var ErrorProxyAuthRequired = NewHALError("Proxy Auth Required", CodeProxyAuthRequired)
View Source
var ErrorRequestEntityTooLarge = NewHALError("Request Entity Too Large", CodeRequestEntityTooLarge)
View Source
var ErrorRequestHeaderFieldsTooLarge = NewHALError("Request Header Fields Too Large", CodeRequestHeaderFieldsTooLarge)
View Source
var ErrorRequestTimeout = NewHALError("Request Timeout", CodeRequestTimeout)
View Source
var ErrorRequestURITooLong = NewHALError("Request URI Too Long", CodeRequestURITooLong)
View Source
var ErrorRequestedRangeNotSatisfiable = NewHALError("Requested Range Not Satisfiable", CodeRequestedRangeNotSatisfiable)
View Source
var ErrorServiceUnavailable = NewHALError("Service Unavailable", CodeServiceUnavailable)
View Source
var ErrorTeapot = NewHALError("Teapot", CodeTeapot)
View Source
var ErrorTooEarly = NewHALError("Too Early", CodeTooEarly)
View Source
var ErrorTooManyRequests = NewHALError("Too Many Requests", CodeTooManyRequests)
View Source
var ErrorUnauthorized = NewHALError("Unauthorized", CodeUnauthorized)
View Source
var ErrorUnavailableForLegalReasons = NewHALError("Unavailable For Legal Reasons", CodeUnavailableForLegalReasons)
View Source
var ErrorUnprocessableEntity = NewHALError("Unprocessable Entity", CodeUnprocessableEntity)
View Source
var ErrorUnsupportedMediaType = NewHALError("Unsupported Media Type", CodeUnsupportedMediaType)
View Source
var ErrorUpgradeRequired = NewHALError("Upgrade Required", CodeUpgradeRequired)
View Source
var ErrorVariantAlsoNegotiates = NewHALError("Variant Also Negotiates", CodeVariantAlsoNegotiates)
View Source
var Errors = map[int]*HALError{
	http.StatusBadRequest:                   ErrorBadRequest,
	http.StatusUnauthorized:                 ErrorUnauthorized,
	http.StatusPaymentRequired:              ErrorPaymentRequired,
	http.StatusForbidden:                    ErrorForbidden,
	http.StatusNotFound:                     ErrorNotFound,
	http.StatusMethodNotAllowed:             ErrorMethodNotAllowed,
	http.StatusNotAcceptable:                ErrorNotAcceptable,
	http.StatusProxyAuthRequired:            ErrorProxyAuthRequired,
	http.StatusRequestTimeout:               ErrorRequestTimeout,
	http.StatusConflict:                     ErrorConflict,
	http.StatusGone:                         ErrorGone,
	http.StatusLengthRequired:               ErrorLengthRequired,
	http.StatusPreconditionFailed:           ErrorPreconditionFailed,
	http.StatusRequestEntityTooLarge:        ErrorRequestEntityTooLarge,
	http.StatusRequestURITooLong:            ErrorRequestURITooLong,
	http.StatusUnsupportedMediaType:         ErrorUnsupportedMediaType,
	http.StatusRequestedRangeNotSatisfiable: ErrorRequestedRangeNotSatisfiable,
	http.StatusExpectationFailed:            ErrorExpectationFailed,
	http.StatusTeapot:                       ErrorTeapot,
	http.StatusMisdirectedRequest:           ErrorMisdirectedRequest,
	http.StatusUnprocessableEntity:          ErrorUnprocessableEntity,
	http.StatusLocked:                       ErrorLocked,
	http.StatusFailedDependency:             ErrorFailedDependency,
	http.StatusTooEarly:                     ErrorTooEarly,
	http.StatusRequestHeaderFieldsTooLarge:  ErrorRequestHeaderFieldsTooLarge,
	http.StatusUnavailableForLegalReasons:   ErrorUnavailableForLegalReasons,

	http.StatusInternalServerError:           ErrorInternalServerError,
	http.StatusNotImplemented:                ErrorNotImplemented,
	http.StatusBadGateway:                    ErrorBadGateway,
	http.StatusServiceUnavailable:            ErrorServiceUnavailable,
	http.StatusGatewayTimeout:                ErrorGatewayTimeout,
	http.StatusHTTPVersionNotSupported:       ErrorHTTPVersionNotSupported,
	http.StatusVariantAlsoNegotiates:         ErrorVariantAlsoNegotiates,
	http.StatusInsufficientStorage:           ErrorInsufficientStorage,
	http.StatusLoopDetected:                  ErrorLoopDetected,
	http.StatusNotExtended:                   ErrorNotExtended,
	http.StatusNetworkAuthenticationRequired: ErrorNetworkAuthenticationRequired,
}

Errors is a mapping of net/http status codes to Error*'s.

Functions

This section is empty.

Types

type Config

type Config struct {
	HideBanner bool
	HidePort   bool
	Debug      bool
}

Config holds all the configuration that is adjustable.

type Context

type Context struct {
	echo.Context
}

Context is essentially a wrapper for echo's context.

type Error

type Error struct {
	Extra   interface{} `json:"extra,omitempty"`
	Code    string      `json:"errcode"`
	Message string      `json:"error"`
}

Error provides the basic JSON fields that are expected by the Matrix specification, and Extra for additional details.

type HALError

type HALError struct {
	representor.HALBody
}

func NewHALError

func NewHALError(m string, c string) *HALError

type Module

type Module struct {
	echo.Group
	Router
}

TODO: These feel weird living in the root directory and should probably be moved.

Module is essentially a wrapper over the echo Group type.

type Route

type Route struct {
	RouteMeta
	Handler echo.HandlerFunc
}

Route defines a Handler and some metadata about the route.

type RouteMeta

type RouteMeta struct {
	Method string `json:"method"`
	Path   string `json:"path"`
	Name   string `json:"name"`
}

RouteMeta is a clone of the echo.Route object that we use to extend our routes with.

type Router

type Router interface {
	Routes() []*Route
}

Router is a group of routes to expose and serve through the server.

type Server

type Server struct {
	Modules []*Module
	// contains filtered or unexported fields
}

Server is the core process.

func New

func New(c Config) *Server

New creates a new instance of Server based on a Config passed to it.

func (*Server) Load

func (s *Server) Load(m *Module)

Load adds a module into the server to expose

func (*Server) Logger

func (s *Server) Logger() echo.Logger

Logger returns the (echo) engine logger.

func (*Server) NewModule

func (s *Server) NewModule(p string, r Router) *Module

NewModule generates the underlying echo Group and register the routes.

func (*Server) Start

func (s *Server) Start(h *http.Server) error

Start begins serving traffic.

func (*Server) Use

func (s *Server) Use(m ...echo.MiddlewareFunc)

TODO: Wrap the MiddlewareFunc better.

Use is a wrapper around echo's Use function.