server

package
v0.0.0-...-e5a5d7c Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(ctx context.Context, writer http.ResponseWriter, err error)

Error handles all error responses for the API.

func NewRouter

func NewRouter(h *Handler) *mux.Router

NewRouter creates the routes to listen

func Respond

func Respond(ctx context.Context, writer http.ResponseWriter, data interface{}, code int)

Respond sends JSON response.

func RespondError

func RespondError(ctx context.Context, writer http.ResponseWriter, err error, code int)

RespondError sends JSON describing the error

func RespondHTML

func RespondHTML(writer http.ResponseWriter, title string, body string, code int)

RespondHTML sends HTML response.

func Start

func Start()

Start creates a server and starts listening

Types

type Endpoint

type Endpoint struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc HandlerFunc
}

Endpoint defines an http endpoint to be queried from an external source

type Handler

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

Handler is the main struct to reference when calling the handling methods

func NewHandler

func NewHandler() *Handler

NewHandler generates a new handler

func (*Handler) Index

func (h *Handler) Index(ctx context.Context, writer http.ResponseWriter, request *http.Request) error

Index method to use as a heartbeat

type HandlerFunc

type HandlerFunc func(context.Context, http.ResponseWriter, *http.Request) error

HandlerFunc is a type that handles a http request

func (HandlerFunc) ServeHTTP

func (fn HandlerFunc) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP needed in http.Handler implemented functions

type ResponseError

type ResponseError struct {
	Error string `json:"error"`
}

ResponseError is an error placeholder to be converted to JSON

Jump to

Keyboard shortcuts

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