Documentation
¶
Index ¶
- func ByteSizeToFriendlyString(length int64) string
- func UnmarshalFromResponse(res *http.Response, model interface{}) error
- type Config
- type Context
- func (ctx *Context) AssertContentLength(max int64) bool
- func (ctx *Context) AssertContentType(allowedContentTypes ...string) bool
- func (ctx *Context) AssertMethod(allowedMethods ...string) bool
- func (ctx *Context) Container() di.Container
- func (ctx *Context) FromJSON(model Purifiable) bool
- func (ctx *Context) GetCorrelationID() id.ID
- func (ctx *Context) GetMiddlewareArtifact(name string) interface{}
- func (ctx *Context) GetPathParameter(name string) string
- func (ctx *Context) GetQueryParameter(name string) string
- func (ctx *Context) Header() http.Header
- func (ctx *Context) InternalServerError(err error)
- func (ctx *Context) NotFound(subjectType string, subject string)
- func (ctx *Context) Request() *http.Request
- func (ctx *Context) Resolve(dependencies ...interface{}) bool
- func (ctx *Context) Respond(code int)
- func (ctx *Context) RespondWithJSON(code int, model interface{})
- func (ctx *Context) ResponseWriter() http.ResponseWriter
- func (ctx *Context) SetMiddlewareArtifact(name string, value interface{})
- type ContextHandlerFunc
- type HandlerBuilder
- type MeasuredResponseWriter
- func (mrw *MeasuredResponseWriter) Duration() time.Duration
- func (mrw *MeasuredResponseWriter) HasWrittenHeaders() bool
- func (mrw *MeasuredResponseWriter) Header() http.Header
- func (mrw *MeasuredResponseWriter) StatusCode() int
- func (mrw *MeasuredResponseWriter) Volume() int64
- func (mrw *MeasuredResponseWriter) Write(b []byte) (int, error)
- func (mrw *MeasuredResponseWriter) WriteHeader(statusCode int)
- type Middleware
- type Purifiable
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteSizeToFriendlyString ¶
ByteSizeToFriendlyString returns the provided byte length as a human-friendly string e.g. 1024 => 1.00 kB.
func UnmarshalFromResponse ¶
UnmarshalFromResponse unmarshals the body of an http.Response to a model.
Types ¶
type Config ¶
type Config struct {
ProblemDetailsTypePrefix string
DebuggingEnabled bool
JSONContentLengthLimit int64
}
Config defines a set of configuration values that dictate how the handler behaves at a global level.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the context of a single HTTP web request. It is not thread-safe.
func NewContext ¶
NewContext creates a new context for the provided request.
func (*Context) AssertContentLength ¶
AssertContentLength ensures that a content length was provided, and that it is in (0, max].
func (*Context) AssertContentType ¶
AssertContentType ensures that the content type of the request matches one of the content types provided.
func (*Context) AssertMethod ¶
AssertMethod ensures that the incoming request is using one of the provided methods.
func (*Context) FromJSON ¶
func (ctx *Context) FromJSON(model Purifiable) bool
FromJSON retrieves JSON from the request body to place into the provided Purifiable.
func (*Context) GetCorrelationID ¶
GetCorrelationID returns the correlationID for the request.
func (*Context) GetMiddlewareArtifact ¶
GetMiddlewareArtifact retrieves the middleware artifact with the specified name. It will return nil if the artifact does not exist.
func (*Context) GetPathParameter ¶
GetPathParameter retrieves a path segment parameter from the request.
func (*Context) GetQueryParameter ¶
GetQueryParameter retrieves a query parameter from the request.
func (*Context) InternalServerError ¶
InternalServerError responds to the request with an InternalServerError status code.
func (*Context) Resolve ¶
Resolve resolves from the underlying container. It will return false if an error prevented the operation from completing.
func (*Context) RespondWithJSON ¶
RespondWithJSON responds to the request with the provided HTTP code and model.
func (*Context) ResponseWriter ¶
func (ctx *Context) ResponseWriter() http.ResponseWriter
ResponseWriter returns the http.ResponseWriter.
func (*Context) SetMiddlewareArtifact ¶
SetMiddlewareArtifact sets the middleware artifact for the specified name.
type ContextHandlerFunc ¶
type ContextHandlerFunc func(ctx *Context)
ContextHandlerFunc is an alias for a function that accepts a Context as its one and only parameter.
type HandlerBuilder ¶
type HandlerBuilder struct {
// contains filtered or unexported fields
}
HandlerBuilder is used to build a handler that can be passed to any HTTP server. Once Build has been called, the HandlerBuilder is invalid and can no longer be used. HandlerBuilder is not thread-safe.
func NewHandlerBuilder ¶
NewHandlerBuilder creates a new handler builder with the provided config and container.
func (*HandlerBuilder) Build ¶
func (b *HandlerBuilder) Build() http.Handler
Build builds a http.Handler that can be passed to any server.
func (*HandlerBuilder) Use ¶
func (b *HandlerBuilder) Use(route Route)
Use adds a route to the list of routes this handler should expose.
type MeasuredResponseWriter ¶
type MeasuredResponseWriter struct {
// contains filtered or unexported fields
}
MeasuredResponseWriter wraps a standard http.ResponseWriter with additional functionality. Specifically, it records the amount of data written, the response code, and the duration of the request/response.
func NewMeasuredResponseWriter ¶
func NewMeasuredResponseWriter(w http.ResponseWriter) *MeasuredResponseWriter
NewMeasuredResponseWriter creates a new MeasuredResponseWriter with the provided underlying http.ResponseWriter.
func (*MeasuredResponseWriter) Duration ¶
func (mrw *MeasuredResponseWriter) Duration() time.Duration
Duration returns the duration between the start of the request and now.
func (*MeasuredResponseWriter) HasWrittenHeaders ¶
func (mrw *MeasuredResponseWriter) HasWrittenHeaders() bool
HasWrittenHeaders returns true if WriteHeader has been called.
func (*MeasuredResponseWriter) Header ¶
func (mrw *MeasuredResponseWriter) Header() http.Header
Header simply returns the headers of the underlying response writer.
func (*MeasuredResponseWriter) StatusCode ¶
func (mrw *MeasuredResponseWriter) StatusCode() int
StatusCode returns the status code that was written for the response. If the status code is yet to be written, or WriteHeader was never explicitly called, StatusCode will return http.StatusOK.
func (*MeasuredResponseWriter) Volume ¶
func (mrw *MeasuredResponseWriter) Volume() int64
Volume returns the number of bytes written to the response writer body.
func (*MeasuredResponseWriter) Write ¶
func (mrw *MeasuredResponseWriter) Write(b []byte) (int, error)
Write writes to the underlying response writer, recording the number of bytes successfully written.
func (*MeasuredResponseWriter) WriteHeader ¶
func (mrw *MeasuredResponseWriter) WriteHeader(statusCode int)
WriteHeader records and writes the header if it has not already been written.
type Middleware ¶
Middleware defines the methods that any HTTP middleware must implement. If the Handle method returns true, the request will continue to be propagated to subsequent middleware handlers and eventually the route handler.
type Purifiable ¶
Purifiable defines the methods that any purifiable request model must implement. The intention is to allow request methods to be able to validate themselves - keeping the validation of user provided information out of routes.
The first return value is the name of the invalid field, the second is the error describing the problem.