Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Metrics ¶ added in v0.11.0
Metrics is middleware which provides tracking of key metrics for incoming HTTP requests.
func Response ¶ added in v0.12.0
func Response(w http.ResponseWriter, errs ...ResponseError)
Response writes http error responses to the http.ResponseWriter. The first error's status will be used to write the http response header.
Types ¶
type ResponseError ¶ added in v0.12.0
type ResponseError struct { // Status is the http status code applicable to this problem. Status int `json:"status,omitempty"` // Detail is a human-readable explanation specific to this occurrence of // the problem. Detail string `json:"detail,omitempty"` }
ResponseError provides additional informatio about problems encounted while performing an operation.
See: https://jsonapi.org/format/#error-objects
func BadRequestError ¶ added in v0.12.0
func BadRequestError(err error) ResponseError
BadRequestError creates a ResponseError with the status of http.StatusBadRequest.
func ConflictError ¶ added in v0.12.0
func ConflictError(err error) ResponseError
ConflictError creates a ResponseError with the status of http.StatusConflict.
func InternalServerError ¶ added in v0.12.0
func InternalServerError(err error) ResponseError
InternalServerError creates a ResponseError with the status of http.StatusInternalServerError.
func NotFoundError ¶ added in v0.12.0
func NotFoundError(err error) ResponseError
NotFoundError creates a ResponseError with the status of http.StatusNotFound.
func NotImplementedError ¶ added in v0.12.0
func NotImplementedError(err error) ResponseError
NotImplementedError creates a ResponseError with the status of http.StatusNotImplemented.
func (ResponseError) Error ¶ added in v0.12.0
func (e ResponseError) Error() string
Error translates the error to a string.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an HTTP server.
func NewServer ¶ added in v0.9.0
func NewServer(opts ...ServerOption) *Server
NewServer creates an HTTP server with and has not started to accept requests yet.
type ServerOption ¶ added in v0.9.0
type ServerOption interface {
// contains filtered or unexported methods
}
ServerOption provides options for configuring the creation of a http server.
func WithMiddleware ¶ added in v0.9.0
func WithMiddleware(mw ...mux.MiddlewareFunc) ServerOption
WithMetricsMiddleware provide middleware service to be added to the server.
func WithServerAddr ¶ added in v0.9.0
func WithServerAddr(addr string) ServerOption
WithServerAddr will configure the server with the listen address.
func WithServerLogger ¶ added in v0.9.0
func WithServerLogger(logger log.Logger) ServerOption
WithServerLogger provides a logger to the server.
func WithServerShutdownTimeout ¶ added in v0.9.0
func WithServerShutdownTimeout(timeout time.Duration) ServerOption
WithServerShutdownTimeout sets the timout for shutting down the server.
func WithServerTLS ¶ added in v0.9.0
func WithServerTLS(cfg *tls.Config) ServerOption
WithServerTLS will configure the server to require TLS.
type Service ¶ added in v0.9.0
type Service interface { // Register will register this service with the given router. Register(router *mux.Router) // Name provides the name of the service. Name() string // Shutdown allows the service to stop any long running background processes it // may have. Shutdown() }
Service defines the methods required by the Server to register with the service with the router.