Documentation ¶
Index ¶
- func BadRequestResponse(w http.ResponseWriter, err error)
- func CreatedResponse(w http.ResponseWriter, r *http.Request, payload interface{}, location string)
- func ErrorResponse(w http.ResponseWriter, err error)
- func NoContentResponse(w http.ResponseWriter)
- func NotAllowedResponse(w http.ResponseWriter, methods []string)
- func NotFoundResponse(w http.ResponseWriter)
- func NotImplementedResponse(w http.ResponseWriter)
- func OkResponse(w http.ResponseWriter, r *http.Request, payload interface{}, ...)
- func OptionsResponse(w http.ResponseWriter, r *http.Request, methods []string, payload interface{})
- func Start(conf *config.Configuration)
- type Modifier
- type MuxWrapper
- type ObservatoryMux
- type ResponseWriterWrapper
- type Server
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.
Types ¶
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 ¶
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.