server

package
v0.0.0-...-08a0563 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2017 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequestResponse

func BadRequestResponse(w http.ResponseWriter, err error)

BadRequestResponse writes a Bad Request response, including error message.

func CreatedResponse

func CreatedResponse(w http.ResponseWriter, r *http.Request, payload interface{}, location string)

CreatedResponse writes a Created response with the given payload and Location header.

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, err error)

ErrorResponse writes an Internal Server Error response, or a Not Found response if the error given is model.ErrNotFound.

func NoContentResponse

func NoContentResponse(w http.ResponseWriter)

NoContentResponse writes a No Content response with headers but no payload.

func NotAllowedResponse

func NotAllowedResponse(w http.ResponseWriter, methods []string)

NotAllowedResponse writes a Method Not Allowed response, including the Allow header.

func NotFoundResponse

func NotFoundResponse(w http.ResponseWriter)

NotFoundResponse writes a Not Found error response.

func NotImplementedResponse

func NotImplementedResponse(w http.ResponseWriter)

NotImplementedResponse writes a Not Yet Implemented response.

func OkResponse

func OkResponse(w http.ResponseWriter, r *http.Request, payload interface{}, lifetime time.Duration)

OkResponse writes a 200 OK response, with the given payload as JSON. Lifetime is used to set caching headers, and if the payload is a Modifier, the Modified header will be set.

func OptionsResponse

func OptionsResponse(w http.ResponseWriter, r *http.Request, methods []string, payload interface{})

OptionsResponse writes a 200 OK response to an OPTIONS request, including the Allow header, with the given payload as JSON. The payload should describe usage of the route.

func Start

func Start(conf *config.Configuration)

Start the REST API server.

Types

type Modifier

type Modifier interface {
	GetModified() time.Time
}

Modifier describes an object that can report the date it was last modified.

type MuxWrapper

type MuxWrapper struct {
	Mux         http.Handler
	Conf        *config.Configuration
	HealthCheck func() bool
}

MuxWrapper wraps an http.Handler, typically a mux, and adds CORS support, GZIP compression, logging, health checking, and basic headers.

func (MuxWrapper) ServeHTTP

func (mw MuxWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ObservatoryMux

type ObservatoryMux struct {
	Conf *config.Configuration
	// contains filtered or unexported fields
}

ObservatoryMux handles routing Observatory REST API requests using compile-time static routing.

func NewObservatoryMux

func NewObservatoryMux(conf *config.Configuration) *ObservatoryMux

NewObservatoryMux constructs a new ObservatoryMux from the given configuration, including static UI serving.

func (ObservatoryMux) ServeHTTP

func (m ObservatoryMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ObservatoryMux) SetHeaders

func (m *ObservatoryMux) SetHeaders(w http.ResponseWriter, r *http.Request)

SetHeaders for general-purpose settings

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	io.Writer
	http.ResponseWriter

	Status int
	Length int
}

ResponseWriterWrapper wraps an http.ResponseWriter and provides writer wrapping and recording of response status and length.

func (*ResponseWriterWrapper) GzipWrap

func (rw *ResponseWriterWrapper) GzipWrap(acceptEncoding, path string) func()

GzipWrap a response writer if the client supports it. Returned function is the Gzip stream closer.

func (*ResponseWriterWrapper) Write

func (rw *ResponseWriterWrapper) Write(b []byte) (int, error)

Write implements io.Writer.Write.

func (*ResponseWriterWrapper) WriteHeader

func (rw *ResponseWriterWrapper) WriteHeader(status int)

WriteHeader implements http.ResponseWriter.WriteHeader.

type Server

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

func New

func New(conf *config.Configuration) *Server

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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