Documentation ¶
Overview ¶
Tiger Tonic [1] is a Go framework for building JSON web services inspired by Dropwizard [2]. If HTML is your game, this will hurt a little.
Like the Go language itself, Tiger Tonic strives to keep features orthogonal. It defers what it can to the Go standard library, go-metrics [3], and a few other packages.
[1] <https://github.com/rcrowley/go-tigertonic> [2] <http://dropwizard.codahale.com> [3] <https://github.com/rcrowley/go-metrics>
Index ¶
- Constants
- Variables
- func Configure(pathname string, i interface{}) error
- func ConfigureJSON(pathname string, i interface{}) error
- func Context(r *http.Request) interface{}
- func NewHTTPEquivError(err error, code int) error
- func RandomBase62Bytes(ii int) []byte
- func RandomBase62String(ii int) string
- func RegisterConfigExt(ext string, f configParser)
- type Accepted
- type ApacheLogger
- type BadGateway
- type BadRequest
- type CORSBuilder
- func (self *CORSBuilder) AddAllowCredentials(allowed bool) *CORSBuilder
- func (self *CORSBuilder) AddAllowedHeaders(headers ...string) *CORSBuilder
- func (self *CORSBuilder) AddAllowedOrigins(origins ...string) *CORSBuilder
- func (self *CORSBuilder) AddExposedHeaders(headers ...string) *CORSBuilder
- func (self *CORSBuilder) Build(handler http.Handler) *CORSHandler
- type CORSHandler
- type CacheControl
- type CacheOptions
- type Conflict
- type Conn
- type ContextHandler
- type Continue
- type Counter
- type CounterByStatus
- type CounterByStatusXX
- type Created
- type Err
- type ErrorWriter
- type ExpectationFailed
- type FirstHandler
- func First(handlers ...http.Handler) FirstHandler
- func HTTPBasicAuth(credentials map[string]string, realm string, h http.Handler) FirstHandler
- func HTTPBasicAuthFunc(f func(string, string) error, realm string, h http.Handler) FirstHandler
- func If(f func(*http.Request) (http.Header, error), h http.Handler) FirstHandler
- type Forbidden
- type Found
- type GatewayTimeout
- type Gone
- type HTTPEquivError
- type HTTPVersionNotSupported
- type HostServeMux
- func (mux HostServeMux) Handle(hostname string, handler http.Handler)
- func (mux HostServeMux) HandleFunc(hostname string, handler func(http.ResponseWriter, *http.Request))
- func (mux HostServeMux) Handler(r *http.Request) (http.Handler, string)
- func (mux HostServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type InternalServerError
- type JSONLogger
- type LengthRequired
- type Listener
- type Logger
- type Marshaler
- type MarshalerError
- type MethodNotAllowed
- type MethodNotAllowedHandler
- type MovedPermanently
- type MultilineLogger
- func (l *MultilineLogger) Output(calldepth int, s string) error
- func (l *MultilineLogger) Print(v ...interface{})
- func (l *MultilineLogger) Printf(format string, v ...interface{})
- func (l *MultilineLogger) Println(v ...interface{})
- func (l *MultilineLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type MultipleChoices
- type NamedError
- type NoContent
- type NonAuthoritativeInfo
- type NotAcceptable
- type NotFound
- type NotFoundHandler
- type NotImplemented
- type NotModified
- type OK
- type PartialContent
- type PaymentRequired
- type PostProcessor
- type PreconditionFailed
- type ProxyAuthRequired
- type Redactor
- type RequestEntityTooLarge
- type RequestID
- type RequestIDCreator
- type RequestTimeout
- type RequestURITooLong
- type RequestedRangeNotSatisfiable
- type ResetContent
- type SeeOther
- type Server
- type ServiceUnavailable
- type SwitchingProtocols
- type Teapot
- type TeeHeaderResponseWriter
- type TeeResponseWriter
- type TemporaryRedirect
- type Timer
- type TrieServeMux
- func (mux *TrieServeMux) Handle(method, pattern string, handler http.Handler)
- func (mux *TrieServeMux) HandleFunc(method, pattern string, handler func(http.ResponseWriter, *http.Request))
- func (mux *TrieServeMux) HandleNamespace(namespace string, handler http.Handler)
- func (mux *TrieServeMux) Handler(r *http.Request) (http.Handler, string)
- func (mux *TrieServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Unauthorized
- type UnsupportedMediaType
- type UseProxy
- type Version
Constants ¶
const ( CORSRequestOrigin string = "Origin" CORSRequestMethod string = "Access-Control-Request-Method" CORSRequestHeaders string = "Access-Control-Request-Headers" )
const ( CORSAllowOrigin string = "Access-Control-Allow-Origin" CORSAllowMethods string = "Access-Control-Allow-Methods" CORSAllowHeaders string = "Access-Control-Allow-Headers" CORSExposeHeaders string = "Access-Control-Expose-Headers" CORSAllowCredentials string = "Access-Control-Allow-Credentials" )
const ONE_YEAR_IN_HOURS = time.Hour * 24 * 365
Variables ¶
var ConfigExt = make(map[string]configParser)
var SnakeCaseHTTPEquivErrors bool
SnakeCaseHTTPEquivErrors being true will cause tigertonic.HTTPEquivError error responses to be written as (for example) "not_found" rather than "tigertonic.NotFound".
Functions ¶
func Configure ¶
Configure delegates reading and unmarshaling of the given configuration file to the appropriate function from ConfigExt. For convenient use with the flags package, an empty pathname is not considered an error.
func ConfigureJSON ¶
ConfigureJSON reads the given configuration file and unmarshals the JSON found into the given configuration structure. For convenient use with the flags package, an empty pathname is not considered an error.
func Context ¶
Context returns the request context as an interface{} given a pointer to the request itself.
func NewHTTPEquivError ¶
Return a new HTTPEquivError whose StatusCode method returns the given status code.
func RandomBase62Bytes ¶
func RandomBase62String ¶
func RegisterConfigExt ¶
func RegisterConfigExt(ext string, f configParser)
Types ¶
type ApacheLogger ¶
type ApacheLogger struct { Logger Logger // contains filtered or unexported fields }
ApacheLogger is an http.Handler that logs requests and responses in the Apache combined log format.
func ApacheLogged ¶
func ApacheLogged(handler http.Handler) *ApacheLogger
ApacheLogged returns an http.Handler that logs requests and responses in the Apache combined log format.
func (*ApacheLogger) Print ¶
func (l *ApacheLogger) Print(v ...interface{})
func (*ApacheLogger) Printf ¶
func (l *ApacheLogger) Printf(format string, v ...interface{})
func (*ApacheLogger) ServeHTTP ¶
func (l *ApacheLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP wraps the http.Request and http.ResponseWriter to log to standard output and pass through to the underlying http.Handler.
type BadGateway ¶
type BadGateway struct {
Err
}
func (BadGateway) Name ¶
func (err BadGateway) Name() string
func (BadGateway) StatusCode ¶
func (err BadGateway) StatusCode() int
type BadRequest ¶
type BadRequest struct {
Err
}
func (BadRequest) Name ¶
func (err BadRequest) Name() string
func (BadRequest) StatusCode ¶
func (err BadRequest) StatusCode() int
type CORSBuilder ¶
type CORSBuilder struct {
// contains filtered or unexported fields
}
CORSBuilder facilitates the application of the same set of CORS rules to a number of endpoints. One would use CORSBuilder.Build() the same way one might wrap a handler in a call to Timed() or Logged().
func NewCORSBuilder ¶
func NewCORSBuilder() *CORSBuilder
func (*CORSBuilder) AddAllowCredentials ¶
func (self *CORSBuilder) AddAllowCredentials(allowed bool) *CORSBuilder
func (*CORSBuilder) AddAllowedHeaders ¶
func (self *CORSBuilder) AddAllowedHeaders(headers ...string) *CORSBuilder
func (*CORSBuilder) AddAllowedOrigins ¶
func (self *CORSBuilder) AddAllowedOrigins(origins ...string) *CORSBuilder
AddAllowedOrigins sets the list of domain for which cross-origin requests are allowed
func (*CORSBuilder) AddExposedHeaders ¶
func (self *CORSBuilder) AddExposedHeaders(headers ...string) *CORSBuilder
func (*CORSBuilder) Build ¶
func (self *CORSBuilder) Build(handler http.Handler) *CORSHandler
type CORSHandler ¶
CORSHandler wraps an http.Handler while correctly handling CORS related functionality, such as Origin headers. It also allows tigertonic core to correctly respond to OPTIONS headers for CORS-enabled endpoints
func (*CORSHandler) HandleCORS ¶
func (self *CORSHandler) HandleCORS(w http.ResponseWriter, r *http.Request)
HandleCORS checks for CORS related request headers and writes the matching response headers for both OPTIONS and regular requests
func (*CORSHandler) ServeHTTP ¶
func (self *CORSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type CacheControl ¶
type CacheControl struct {
// contains filtered or unexported fields
}
CacheControl is an http.Handler that sets cache headers.
func Cached ¶
func Cached(handler http.Handler, o CacheOptions) *CacheControl
Cached returns an http.Handler that sets appropriate Cache headers on the outgoing response and passes requests to a wrapped http.Handler.
func (*CacheControl) ServeHTTP ¶
func (c *CacheControl) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP sets the header and passes the request and response to the wrapped http.Handler
type CacheOptions ¶
type CacheOptions struct { Immutable bool IsPrivate bool NoCache bool NoStore bool NoTransform bool MustRevalidate bool ProxyRevalidate bool MaxAge time.Duration }
These set the relevant headers in the response per http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
func (CacheOptions) String ¶
func (o CacheOptions) String() string
type Conn ¶
Conn is just a net.Conn that accounts for itself so the listener can be stopped gracefully.
type ContextHandler ¶
type ContextHandler struct {
// contains filtered or unexported fields
}
ContextHandler is an http.Handler that associates a context object of any type with each request it handles.
func WithContext ¶
func WithContext(handler http.Handler, i interface{}) *ContextHandler
WithContext wraps an http.Handler and associates a new context object of the same type as the second parameter with each request it handles. You must wrap any handler that uses Context or the four-parameter form of Marshaled in WithContext.
func (*ContextHandler) ServeHTTP ¶
func (ch *ContextHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP adds and removes the per-request context and calls the wrapped http.Handler in between.
type Counter ¶
type Counter struct { metrics.Counter // contains filtered or unexported fields }
Counter is an http.Handler that counts requests via go-metrics.
type CounterByStatus ¶
type CounterByStatus struct {
// contains filtered or unexported fields
}
CounterByStatus is an http.Handler that counts responses by their HTTP status code via go-metrics.
func CountedByStatus ¶
func CountedByStatus( handler http.Handler, name string, registry metrics.Registry, ) *CounterByStatus
CountedByStatus returns an http.Handler that passes requests to an underlying http.Handler and then counts the response by its HTTP status code via go-metrics.
func (*CounterByStatus) ServeHTTP ¶
func (c *CounterByStatus) ServeHTTP(w0 http.ResponseWriter, r *http.Request)
ServeHTTP passes the request to the underlying http.Handler and then counts the response by its HTTP status code via go-metrics.
type CounterByStatusXX ¶
type CounterByStatusXX struct {
// contains filtered or unexported fields
}
CounterByStatusXX is an http.Handler that counts responses by the first digit of their HTTP status code via go-metrics.
func CountedByStatusXX ¶
func CountedByStatusXX( handler http.Handler, name string, registry metrics.Registry, ) *CounterByStatusXX
CountedByStatusXX returns an http.Handler that passes requests to an underlying http.Handler and then counts the response by the first digit of its HTTP status code via go-metrics.
func (*CounterByStatusXX) ServeHTTP ¶
func (c *CounterByStatusXX) ServeHTTP(w0 http.ResponseWriter, r *http.Request)
ServeHTTP passes the request to the underlying http.Handler and then counts the response by its HTTP status code via go-metrics.
type Err ¶
type Err error
Err is an alias for the built-in error type so that it can be publicly exported when embedding.
type ErrorWriter ¶
type ErrorWriter interface { WriteError(r *http.Request, w http.ResponseWriter, err error) WriteJSONError(w http.ResponseWriter, err error) WritePlaintextError(w http.ResponseWriter, err error) }
var ResponseErrorWriter ErrorWriter = defaultErrorWriter{}
ResponseErrorWriter is a handler for outputting errors to the http.ResponseWriter
type ExpectationFailed ¶
type ExpectationFailed struct {
Err
}
func (ExpectationFailed) Name ¶
func (err ExpectationFailed) Name() string
func (ExpectationFailed) StatusCode ¶
func (err ExpectationFailed) StatusCode() int
type FirstHandler ¶
FirstHandler is an http.Handler that, for each handler in its slice of handlers, calls ServeHTTP until the first one that calls w.WriteHeader.
func First ¶
func First(handlers ...http.Handler) FirstHandler
First returns an http.Handler that, for each handler in its slice of handlers, calls ServeHTTP until the first one that calls w.WriteHeader.
func HTTPBasicAuth ¶
HTTPBasicAuth returns an http.Handler that conditionally calls another http.Handler if the request includes an Authorization header with a username and password that appear in the map of credentials. Otherwise, respond 401 Unauthorized.
func HTTPBasicAuthFunc ¶
HTTPBasicAuthFunc returns an http.Handler that conditionally calls another http.Handler if the request includes an Authorization header with a username and password that produce a nil error when passed to the given function. Otherwise, respond 401 Unauthorized.
func If ¶
If returns an http.Handler that conditionally calls another http.Handler unless the given function returns an error. In that case, the error is used to create a plaintext or JSON response as dictated by the Accept header.
func (FirstHandler) ServeHTTP ¶
func (fh FirstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP calls each handler in its slice of handlers until the first one that calls w.WriteHeader.
type GatewayTimeout ¶
type GatewayTimeout struct {
Err
}
func (GatewayTimeout) Name ¶
func (err GatewayTimeout) Name() string
func (GatewayTimeout) StatusCode ¶
func (err GatewayTimeout) StatusCode() int
type HTTPEquivError ¶
type HTTPVersionNotSupported ¶
type HTTPVersionNotSupported struct {
Err
}
func (HTTPVersionNotSupported) Name ¶
func (err HTTPVersionNotSupported) Name() string
func (HTTPVersionNotSupported) StatusCode ¶
func (err HTTPVersionNotSupported) StatusCode() int
type HostServeMux ¶
HostServeMux is an HTTP request multiplexer that implements http.Handler with an API similar to http.ServeMux. It is only sensitive to the hostname and doesn't even look at the rest of the request.
func NewHostServeMux ¶
func NewHostServeMux() HostServeMux
NewHostServeMux makes a new HostServeMux.
func (HostServeMux) Handle ¶
func (mux HostServeMux) Handle(hostname string, handler http.Handler)
Handle registers an http.Handler for the given hostname.
func (HostServeMux) HandleFunc ¶
func (mux HostServeMux) HandleFunc(hostname string, handler func(http.ResponseWriter, *http.Request))
HandleFunc registers a handler function for the given hostname.
func (HostServeMux) ServeHTTP ¶
func (mux HostServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP routes an HTTP request to the http.Handler registered for the requested hostname. It responds 404 if the hostname is not registered.
type InternalServerError ¶
type InternalServerError struct {
Err
}
func (InternalServerError) Name ¶
func (err InternalServerError) Name() string
func (InternalServerError) StatusCode ¶
func (err InternalServerError) StatusCode() int
type JSONLogger ¶
type JSONLogger struct { Logger Logger RequestIDCreator RequestIDCreator // contains filtered or unexported fields }
JSONLogged is an http.Handler that logs requests and responses in a parse-able json line. complete with paths, statuses, headers, and bodies. Sensitive information may be redacted by a user-defined function.
func JSONLogged ¶
func JSONLogged(handler http.Handler, redactor Redactor) *JSONLogger
JSONLogged returns an http.Handler that logs requests and responses in a parse-able json line. complete with paths, statuses, headers, and bodies. Sensitive information may be redacted by a user-defined function.
func (*JSONLogger) Print ¶
func (jl *JSONLogger) Print(v ...interface{})
func (*JSONLogger) Printf ¶
func (jl *JSONLogger) Printf(format string, v ...interface{})
func (*JSONLogger) Println ¶
func (jl *JSONLogger) Println(v ...interface{})
func (*JSONLogger) ServeHTTP ¶
func (jl *JSONLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP wraps the http.Request and http.ResponseWriter to capture the input and output for logging
type LengthRequired ¶
type LengthRequired struct {
Err
}
func (LengthRequired) Name ¶
func (err LengthRequired) Name() string
func (LengthRequired) StatusCode ¶
func (err LengthRequired) StatusCode() int
type Listener ¶
Listener is just a net.Listener that accounts for connections it accepts so it can be stopped gracefully.
type Marshaler ¶
type Marshaler struct {
// contains filtered or unexported fields
}
Marshaler is an http.Handler that unmarshals JSON input, handles the request via a function, and marshals JSON output. It refuses to answer requests without an Accept header that includes the application/json content type.
func Marshaled ¶
func Marshaled(i interface{}) *Marshaler
Marshaled returns an http.Handler that implements its ServeHTTP method by calling the given function, the signature of which must be
func(*url.URL, http.Header, *Request) (int, http.Header, *Response)
where Request and Response may be any struct type of your choosing.
func (*Marshaler) ServeHTTP ¶
func (m *Marshaler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP unmarshals JSON input, handles the request via the function, and marshals JSON output. If the output of the handler function implements io.Reader the headers must contain a 'Content-Type'; the stream will be written directly to the requestor without being marshaled to JSON. Additionally if the output implements the io.Closer the stream will be automatically closed after flushing.
type MarshalerError ¶
type MarshalerError string
MarshalerError is the response body for some 500 responses and panics when a handler function is not suitable.
func NewMarshalerError ¶
func NewMarshalerError(format string, args ...interface{}) MarshalerError
func (MarshalerError) Error ¶
func (e MarshalerError) Error() string
type MethodNotAllowed ¶
type MethodNotAllowed struct {
Err
}
func (MethodNotAllowed) Name ¶
func (err MethodNotAllowed) Name() string
func (MethodNotAllowed) StatusCode ¶
func (err MethodNotAllowed) StatusCode() int
type MethodNotAllowedHandler ¶
type MethodNotAllowedHandler struct {
// contains filtered or unexported fields
}
MethodNotAllowedHandler responds 405 to every request with an Allow header and possibly with a JSON body.
func (MethodNotAllowedHandler) ServeHTTP ¶
func (h MethodNotAllowedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type MovedPermanently ¶
type MovedPermanently struct {
Err
}
func (MovedPermanently) Name ¶
func (err MovedPermanently) Name() string
func (MovedPermanently) StatusCode ¶
func (err MovedPermanently) StatusCode() int
type MultilineLogger ¶
type MultilineLogger struct { Logger Logger RequestIDCreator RequestIDCreator // contains filtered or unexported fields }
MultilineLogger is an http.Handler that logs requests and responses, complete with paths, statuses, headers, and bodies. Sensitive information may be redacted by a user-defined function.
func Logged ¶
func Logged(handler http.Handler, redactor Redactor) *MultilineLogger
Logged returns an http.Handler that logs requests and responses, complete with paths, statuses, headers, and bodies. Sensitive information may be redacted by a user-defined function.
func (*MultilineLogger) Output ¶
func (l *MultilineLogger) Output(calldepth int, s string) error
Output overrides log.Logger's Output method, calling our redactor first.
func (*MultilineLogger) Print ¶
func (l *MultilineLogger) Print(v ...interface{})
Print is identical to log.Logger's Print but uses our overridden Output.
func (*MultilineLogger) Printf ¶
func (l *MultilineLogger) Printf(format string, v ...interface{})
Printf is identical to log.Logger's Print but uses our overridden Output.
func (*MultilineLogger) Println ¶
func (l *MultilineLogger) Println(v ...interface{})
Println is identical to log.Logger's Print but uses our overridden Output.
func (*MultilineLogger) ServeHTTP ¶
func (l *MultilineLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP wraps the http.Request and http.ResponseWriter to log to standard output and pass through to the underlying http.Handler.
type MultipleChoices ¶
type MultipleChoices struct {
Err
}
func (MultipleChoices) Name ¶
func (err MultipleChoices) Name() string
func (MultipleChoices) StatusCode ¶
func (err MultipleChoices) StatusCode() int
type NamedError ¶
type NonAuthoritativeInfo ¶
type NonAuthoritativeInfo struct {
Err
}
func (NonAuthoritativeInfo) Name ¶
func (err NonAuthoritativeInfo) Name() string
func (NonAuthoritativeInfo) StatusCode ¶
func (err NonAuthoritativeInfo) StatusCode() int
type NotAcceptable ¶
type NotAcceptable struct {
Err
}
func (NotAcceptable) Name ¶
func (err NotAcceptable) Name() string
func (NotAcceptable) StatusCode ¶
func (err NotAcceptable) StatusCode() int
type NotFoundHandler ¶
type NotFoundHandler struct{}
NotFoundHandler responds 404 to every request, possibly with a JSON body.
func (NotFoundHandler) ServeHTTP ¶
func (NotFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type NotImplemented ¶
type NotImplemented struct {
Err
}
func (NotImplemented) Name ¶
func (err NotImplemented) Name() string
func (NotImplemented) StatusCode ¶
func (err NotImplemented) StatusCode() int
type NotModified ¶
type NotModified struct {
Err
}
func (NotModified) Name ¶
func (err NotModified) Name() string
func (NotModified) StatusCode ¶
func (err NotModified) StatusCode() int
type PartialContent ¶
type PartialContent struct {
Err
}
func (PartialContent) Name ¶
func (err PartialContent) Name() string
func (PartialContent) StatusCode ¶
func (err PartialContent) StatusCode() int
type PaymentRequired ¶
type PaymentRequired struct {
Err
}
func (PaymentRequired) Name ¶
func (err PaymentRequired) Name() string
func (PaymentRequired) StatusCode ¶
func (err PaymentRequired) StatusCode() int
type PostProcessor ¶
type PostProcessor struct {
// contains filtered or unexported fields
}
func PostProcessed ¶
func (*PostProcessor) ServeHTTP ¶
func (pp *PostProcessor) ServeHTTP(w0 http.ResponseWriter, r *http.Request)
type PreconditionFailed ¶
type PreconditionFailed struct {
Err
}
func (PreconditionFailed) Name ¶
func (err PreconditionFailed) Name() string
func (PreconditionFailed) StatusCode ¶
func (err PreconditionFailed) StatusCode() int
type ProxyAuthRequired ¶
type ProxyAuthRequired struct {
Err
}
func (ProxyAuthRequired) Name ¶
func (err ProxyAuthRequired) Name() string
func (ProxyAuthRequired) StatusCode ¶
func (err ProxyAuthRequired) StatusCode() int
type Redactor ¶
A Redactor is a function that takes and returns a string. It is called to allow sensitive information to be redacted before it is logged.
type RequestEntityTooLarge ¶
type RequestEntityTooLarge struct {
Err
}
func (RequestEntityTooLarge) Name ¶
func (err RequestEntityTooLarge) Name() string
func (RequestEntityTooLarge) StatusCode ¶
func (err RequestEntityTooLarge) StatusCode() int
type RequestID ¶
type RequestID string
A unique RequestID is given to each request and is included with each line of each log entry.
func NewRequestID ¶
func NewRequestID() RequestID
NewRequestID returns a new 16-character random RequestID.
type RequestIDCreator ¶
A RequestIDCreator is a function that takes a request and returns a unique RequestID for it.
type RequestTimeout ¶
type RequestTimeout struct {
Err
}
func (RequestTimeout) Name ¶
func (err RequestTimeout) Name() string
func (RequestTimeout) StatusCode ¶
func (err RequestTimeout) StatusCode() int
type RequestURITooLong ¶
type RequestURITooLong struct {
Err
}
func (RequestURITooLong) Name ¶
func (err RequestURITooLong) Name() string
func (RequestURITooLong) StatusCode ¶
func (err RequestURITooLong) StatusCode() int
type RequestedRangeNotSatisfiable ¶
type RequestedRangeNotSatisfiable struct {
Err
}
func (RequestedRangeNotSatisfiable) Name ¶
func (err RequestedRangeNotSatisfiable) Name() string
func (RequestedRangeNotSatisfiable) StatusCode ¶
func (err RequestedRangeNotSatisfiable) StatusCode() int
type ResetContent ¶
type ResetContent struct {
Err
}
func (ResetContent) Name ¶
func (err ResetContent) Name() string
func (ResetContent) StatusCode ¶
func (err ResetContent) StatusCode() int
type Server ¶
Server is an http.Server with better defaults and built-in graceful stop.
func NewTLSServer ¶
NewTLSServer returns an http.Server with better defaults configured to use the certificate and private key files.
func (*Server) Close ¶
Close closes all the net.Listeners passed to Serve (even via ListenAndServe) and signals open connections to close at their earliest convenience. That is either after responding to the current request or after a short grace period for idle keepalive connections. Close blocks until all connections have been closed.
func (*Server) ListenAndServe ¶
ListenAndServe calls net.Listen with s.Addr and then calls s.Serve.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS calls s.TLS with the given certificate and private key files and then calls s.ListenAndServe.
type ServiceUnavailable ¶
type ServiceUnavailable struct {
}func (ServiceUnavailable) Name ¶
func (err ServiceUnavailable) Name() string
func (ServiceUnavailable) StatusCode ¶
func (err ServiceUnavailable) StatusCode() int
type SwitchingProtocols ¶
type SwitchingProtocols struct {
Err
}
func (SwitchingProtocols) Name ¶
func (err SwitchingProtocols) Name() string
func (SwitchingProtocols) StatusCode ¶
func (err SwitchingProtocols) StatusCode() int
type TeeHeaderResponseWriter ¶
type TeeHeaderResponseWriter struct { http.Flusher http.ResponseWriter StatusCode int }
TeeHeaderResponseWriter is an http.ResponseWriter that both writes and records the response status and headers for post-processing.
func NewTeeHeaderResponseWriter ¶
func NewTeeHeaderResponseWriter(w http.ResponseWriter) *TeeHeaderResponseWriter
NewTeeHeaderResponseWriter constructs a new TeeHeaderResponseWriter that writes responses through another http.ResponseWriter and records the response status and headers for post-processing.
func (*TeeHeaderResponseWriter) Flush ¶
func (w *TeeHeaderResponseWriter) Flush()
Flush implements the http.Flusher interface, if possible, to support streaming responses to clients.
func (*TeeHeaderResponseWriter) WriteHeader ¶
func (w *TeeHeaderResponseWriter) WriteHeader(code int)
WriteHeader writes the response line and headers to the client via the underlying http.ResponseWriter and records the status for post-processing.
type TeeResponseWriter ¶
TeeResponseWriter is an http.ResponseWriter that both writes and records the response status, headers, and body for post-processing.
func NewTeeResponseWriter ¶
func NewTeeResponseWriter(w http.ResponseWriter) *TeeResponseWriter
NewTeeResponseWriter constructs a new TeeResponseWriter that writes responses through another http.ResponseWriter and records the response status, headers, and body for post-processing.
func (*TeeResponseWriter) Flush ¶
func (w *TeeResponseWriter) Flush()
Flush implements the http.Flusher interface, if possible, to support streaming responses to clients.
func (*TeeResponseWriter) Write ¶
func (w *TeeResponseWriter) Write(p []byte) (int, error)
Write writes the byte slice to the client via the underlying http.ResponseWriter and records it for post-processing.
func (*TeeResponseWriter) WriteHeader ¶
func (w *TeeResponseWriter) WriteHeader(code int)
WriteHeader writes the response line and headers to the client via the underlying http.ResponseWriter and records the status for post-processing.
type TemporaryRedirect ¶
type TemporaryRedirect struct {
Err
}
func (TemporaryRedirect) Name ¶
func (err TemporaryRedirect) Name() string
func (TemporaryRedirect) StatusCode ¶
func (err TemporaryRedirect) StatusCode() int
type Timer ¶
type Timer struct { metrics.Timer // contains filtered or unexported fields }
Timer is an http.Handler that counts requests via go-metrics.
type TrieServeMux ¶
type TrieServeMux struct {
// contains filtered or unexported fields
}
TrieServeMux is an HTTP request multiplexer that implements http.Handler with an API similar to http.ServeMux. It is expanded to be sensitive to the HTTP method and treats URL patterns as patterns rather than simply prefixes.
Components of the URL pattern surrounded by braces (for example: "{foo}") match any string and create an entry for the string plus the string surrounded by braces in the query parameters (for example: "foo" and "{foo}").
func NewTrieServeMux ¶
func NewTrieServeMux() *TrieServeMux
NewTrieServeMux makes a new TrieServeMux.
func (*TrieServeMux) Handle ¶
func (mux *TrieServeMux) Handle(method, pattern string, handler http.Handler)
Handle registers an http.Handler for the given HTTP method and URL pattern.
func (*TrieServeMux) HandleFunc ¶
func (mux *TrieServeMux) HandleFunc(method, pattern string, handler func(http.ResponseWriter, *http.Request))
HandleFunc registers a handler function for the given HTTP method and URL pattern.
func (*TrieServeMux) HandleNamespace ¶
func (mux *TrieServeMux) HandleNamespace(namespace string, handler http.Handler)
HandleNamespace registers an http.Handler for the given URL namespace. The matching namespace is stripped from the URL before it is passed to the underlying http.Handler.
func (*TrieServeMux) Handler ¶
Handler returns the handler to use for the given HTTP request and mutates the querystring to add wildcards extracted from the URL.
It sanitizes out any query params that might collide with params parsed from the URL to avoid surprises. See TestCollidingQueryParam for the use case
func (*TrieServeMux) ServeHTTP ¶
func (mux *TrieServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP routes an HTTP request to the http.Handler registered for the URL pattern which matches the requested path. It responds 404 if there is no matching URL pattern and 405 if the requested HTTP method is not allowed.
type Unauthorized ¶
type Unauthorized struct {
}func (Unauthorized) Name ¶
func (err Unauthorized) Name() string
func (Unauthorized) StatusCode ¶
func (err Unauthorized) StatusCode() int
type UnsupportedMediaType ¶
type UnsupportedMediaType struct {
Err
}
func (UnsupportedMediaType) Name ¶
func (err UnsupportedMediaType) Name() string
func (UnsupportedMediaType) StatusCode ¶
func (err UnsupportedMediaType) StatusCode() int
Source Files ¶
- base62.go
- cache.go
- config.go
- context.go
- cors.go
- error.go
- host_serve_mux.go
- http_basic_auth.go
- http_equiv_error.go
- json_logger.go
- logger.go
- marshaler.go
- method_not_allowed.go
- metrics.go
- middleware.go
- named_error.go
- net.go
- not_found.go
- post_processor.go
- server.go
- tee.go
- test_response_writer.go
- tigertonic.go
- trie_serve_mux.go
- version.go