tigertonic

package module
v0.0.0-...-1c4fc87 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2013 License: BSD-2-Clause-Views Imports: 26 Imported by: 0

README

Tiger Tonic

A Go framework for building JSON web services inspired by Dropwizard. 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 and a few other packages.

Documentation: http://godoc.org/github.com/rcrowley/go-tigertonic

Development mailing list: https://groups.google.com/forum/#!forum/tigertonic-dev

Users mailing list: https://groups.google.com/forum/#!forum/tigertonic-users

tigertonic.TrieServeMux

HTTP routing in the Go standard library is pretty anemic. Enter tigertonic.TrieServeMux. It accepts an HTTP method, a URL pattern, and an http.Handler or an http.HandlerFunc. Components in the URL pattern wrapped in curly braces - { and } - are wildcards: their values are added to the URL as u.Query().Get("name").

HandleNamespace is like Handle but additionally strips the namespace from the URL, making API versioning, multitenant services, and relative links easier to manage.

tigertonic.HostServeMux

Use tigertonic.HostServeMux to serve multiple domain names from the same net.Listener.

tigertonic.Marshaled

Wrap a function in tigertonic.Marshaled to turn it into an http.Handler. The function signature must be something like this or tigertonic.Marshaled will panic:

func myHandler(*url.URL, http.Header, *MyRequest) (int, http.Header, *MyResponse, error)

Request bodies will be unmarshaled into a MyRequest struct and response bodies will be marshaled from MyResponse structs.

Should you need to respond with an error, the tigertonic.HTTPEquivError interface is implemented by tigertonic.BadRequest (and so on for every other HTTP response status) that can be wrapped around any error:

func myHandler(*url.URL, http.Header, *MyRequest) (int, http.Header, *MyResponse, error) {
    return 0, nil, nil, tigertonic.BadRequest{errors.New("Bad Request")}
}

Alternatively, you can return a valid status as the first output parameter and an error as the last; that status will be used in the error response.

tigertonic.Logged and tigertonic.ApacheLogged

Wrap an http.Handler in tigertonic.Logged to have the request and response headers and bodies logged to standard output. The second argument is an optional func(string) string called as requests and responses are logged to give the caller the opportunity to redact sensitive information from log entries.

Wrap an http.Handler in tigertonic.ApacheLogged to have the request and response logged in the more traditional Apache combined log format.

tigertonic.Counted and tigertonic.Timed

Wrap an http.Handler in tigertonic.Counted or tigertonic.Timed to have the request counted or timed with go-metrics.

tigertonic.First

Call tigertonic.First with a variadic slice of http.Handlers. It will call ServeHTTP on each in succession until the first one that calls w.WriteHeader.

tigertonic.If

tigertonic.If expresses the most common use of tigertonic.First more naturally. Call tigertonic.If with a func(*http.Request) (http.Header, error) and an http.Handler. It will conditionally call the handler unless the function returns an error. In that case, the error is used to create a response.

tigertonic.HTTPBasicAuth

Wrap an http.Handler in tigertonic.HTTPBasicAuth, providing a map[string]string of authorized usernames to passwords, to require the request include a valid Authorization header.

tigertonic.CORSHandler and tigertonic.CORSBuilder

Wrap an http.Handler in tigertonic.CORSHandler (using CORSBuilder.Build()) to inject CORS-related headers. Currently only Origin-related headers (used for cross-origin browser requests) are supported.

tigertonic.Configure

Call tigertonic.Configure to read and unmarshal a JSON configuration file into a configuration structure of your own design. This is mere convenience and what you do with it after is up to you.

tigertonic.WithContext and tigertonic.Context

Wrap an http.Handler and a zero value of any non-interface type in tigertonic.WithContext to enable per-request context. Each request may call tigertonic.Context with the *http.Request in progress to get a pointer to the context which is of the type passed to tigertonic.WithContext.

Usage

Install dependencies:

sh bootstrap.sh

Then define your service. The working example may be a more convenient place to start.

Requests that have bodies have types. JSON is deserialized by adding tigertonic.Marshaled to your routes.

type MyRequest struct {
	ID     string      `json:"id"`
	Stuff  interface{} `json:"stuff"`
}

Responses, too, have types. JSON is serialized by adding tigertonic.Marshaled to your routes.

type MyResponse struct {
	ID     string      `json:"id"`
	Stuff  interface{} `json:"stuff"`
}

Routes are just functions with a particular signature. You control the request and response types.

func myHandler(u *url.URL, h http.Header, *MyRequest) (int, http.Header, *MyResponse, error) {
    return http.StatusOK, nil, &MyResponse{"ID", "STUFF"}, nil
}

Wire it all up in main.main!

mux := tigertonic.NewTrieServeMux()
mux.Handle("GET", "/stuff", tigertonic.Marshaled(tigertonic.Timed(myHandler, "myHandler", nil)))
tigertonic.NewServer(":8000", tigertonic.Logged(mux, nil)).ListenAndServe()

Ready for more? See the full example. Build it with go build, run it with ./example, and test it out:

curl -H"Host: example.com" -sv "http://127.0.0.1:8000/1.0/stuff/ID"
curl -H"Host: example.com" -X"POST" -d'{"id":"ID","stuff":"STUFF"}' -sv "http://127.0.0.1:8000/1.0/stuff"
curl -H"Host: example.com" -X"POST" -d'{"id":"ID","stuff":"STUFF"}' -sv "http://127.0.0.1:8000/1.0/stuff/ID"
curl -H"Host: example.com" -sv "http://127.0.0.1:8000/1.0/forbidden"

WTF?

Dropwizard was named after http://gunshowcomic.com/316 so Tiger Tonic was named after http://gunshowcomic.com/338.

If Tiger Tonic isn't your cup of tea, perhaps one of these fine tools suits you:

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

View Source
const CORSAllowHeaders string = "Access-Control-Allow-Headers"
View Source
const CORSAllowMethods string = "Access-Control-Allow-Methods"
View Source
const CORSAllowOrigin string = "Access-Control-Allow-Origin"
View Source
const CORSRequestHeaders string = "Access-Control-Request-Headers"
View Source
const CORSRequestMethod string = "Access-Control-Request-Method"
View Source
const CORSRequestOrigin string = "Origin"

Variables

View Source
var ConfigExt = map[string]func(string, interface{}) error{
	".json": ConfigureJSON,
}

ConfigExt maps all known configuration file extensions to their read-and-unmarshal functions.

View Source
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

func Configure(pathname string, i interface{}) error

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

func ConfigureJSON(pathname string, i interface{}) error

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

func Context(r *http.Request) interface{}

Context returns the request context as an interface{} given a pointer to the request itself.

func RandomBase62Bytes

func RandomBase62Bytes(ii int) []byte

func RandomBase62String

func RandomBase62String(ii int) string

Types

type Accepted

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

func (Accepted) Status

func (err Accepted) Status() int

type ApacheLogger

type ApacheLogger struct {
	*log.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) ServeHTTP

func (al *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 {
	// contains filtered or unexported fields
}

func (BadGateway) Status

func (err BadGateway) Status() int

type BadRequest

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

func (BadRequest) Status

func (err BadRequest) Status() int

type CORSBuilder

type CORSBuilder struct {
	http.Header
	// contains filtered or unexported fields
}

CRSBuilder 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) AddAllowedHeaders

func (self *CORSBuilder) AddAllowedHeaders(headers ...string) *CORSBuilder

func (*CORSBuilder) Build

func (self *CORSBuilder) Build(handler http.Handler) *CORSHandler

func (*CORSBuilder) SetAllowedOrigin

func (self *CORSBuilder) SetAllowedOrigin(origin string) *CORSBuilder

SetAllowedOrigin sets the domain for which cross-origin requests are allowed

type CORSHandler

type CORSHandler struct {
	http.Handler
	Header http.Header
}

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) ServeHTTP

func (self *CORSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Conflict

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

func (Conflict) Status

func (err Conflict) Status() int

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 Continue

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

func (Continue) Status

func (err Continue) Status() int

type Counter

type Counter struct {
	metrics.Counter
	// contains filtered or unexported fields
}

Counter is an http.Handler that counts requests via go-metrics.

func Counted

func Counted(handler http.Handler, name string, registry metrics.Registry) *Counter

Counted returns an http.Handler that passes requests to an underlying http.Handler and then counts the request via go-metrics.

func (*Counter) ServeHTTP

func (c *Counter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP passes the request to the underlying http.Handler and then counts the request via go-metrics.

type Created

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

func (Created) Status

func (err Created) Status() int

type ExpectationFailed

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

func (ExpectationFailed) Status

func (err ExpectationFailed) Status() int

type FirstHandler

type FirstHandler []http.Handler

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

func HTTPBasicAuth(credentials map[string]string, realm string, h http.Handler) FirstHandler

HTTPBasicAuth returns an http.Handler that conditionally calls another http.Handler if the request includes and Authorization header with a username and password that appear in the map of credentials. Otherwise, respond 401 Unauthorized.

func If

func If(f func(*http.Request) (http.Header, error), h http.Handler) FirstHandler

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 Forbidden

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

func (Forbidden) Status

func (err Forbidden) Status() int

type Found

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

func (Found) Status

func (err Found) Status() int

type GatewayTimeout

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

func (GatewayTimeout) Status

func (err GatewayTimeout) Status() int

type Gone

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

func (Gone) Status

func (err Gone) Status() int

type HTTPEquivError

type HTTPEquivError interface {
	error
	Status() int
}

type HTTPVersionNotSupported

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

func (HTTPVersionNotSupported) Status

func (err HTTPVersionNotSupported) Status() int

type HostServeMux

type HostServeMux map[string]http.Handler

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) Handler

func (mux HostServeMux) Handler(r *http.Request) (http.Handler, string)

Handler returns the handler to use for the given HTTP request.

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 {
	// contains filtered or unexported fields
}

func (InternalServerError) Status

func (err InternalServerError) Status() int

type LengthRequired

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

func (LengthRequired) Status

func (err LengthRequired) Status() int

type Logger

type Logger struct {
	*log.Logger

	RequestIDCreator RequestIDCreator
	// contains filtered or unexported fields
}

Logger 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) *Logger

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 (*Logger) Output

func (l *Logger) Output(calldepth int, s string) error

Output overrides log.Logger's Output method, calling our redactor first.

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print is identical to log.Logger's Print but uses our overridden Output.

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf is identical to log.Logger's Print but uses our overridden Output.

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

Println is identical to log.Logger's Print but uses our overridden Output.

func (*Logger) ServeHTTP

func (l *Logger) 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 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.

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 {
	// contains filtered or unexported fields
}

func (MethodNotAllowed) Status

func (err MethodNotAllowed) Status() 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

type MovedPermanently

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

func (MovedPermanently) Status

func (err MovedPermanently) Status() int

type MultipleChoices

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

func (MultipleChoices) Status

func (err MultipleChoices) Status() int

type NamedError

type NamedError interface {
	error
	Name() string
}

type NoContent

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

func (NoContent) Status

func (err NoContent) Status() int

type NonAuthoritativeInfo

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

func (NonAuthoritativeInfo) Status

func (err NonAuthoritativeInfo) Status() int

type NotAcceptable

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

func (NotAcceptable) Status

func (err NotAcceptable) Status() int

type NotFound

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

func (NotFound) Status

func (err NotFound) Status() 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 {
	// contains filtered or unexported fields
}

func (NotImplemented) Status

func (err NotImplemented) Status() int

type NotModified

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

func (NotModified) Status

func (err NotModified) Status() int

type OK

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

func (OK) Status

func (err OK) Status() int

type PartialContent

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

func (PartialContent) Status

func (err PartialContent) Status() int

type PaymentRequired

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

func (PaymentRequired) Status

func (err PaymentRequired) Status() int

type PreconditionFailed

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

func (PreconditionFailed) Status

func (err PreconditionFailed) Status() int

type ProxyAuthRequired

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

func (ProxyAuthRequired) Status

func (err ProxyAuthRequired) Status() int

type Redactor

type Redactor func(string) string

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 {
	// contains filtered or unexported fields
}

func (RequestEntityTooLarge) Status

func (err RequestEntityTooLarge) Status() 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

type RequestIDCreator func(r *http.Request) RequestID

A RequestIDCreator is a function that takes a request and returns a unique RequestID for it.

type RequestTimeout

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

func (RequestTimeout) Status

func (err RequestTimeout) Status() int

type RequestURITooLong

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

func (RequestURITooLong) Status

func (err RequestURITooLong) Status() int

type RequestedRangeNotSatisfiable

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

func (RequestedRangeNotSatisfiable) Status

func (err RequestedRangeNotSatisfiable) Status() int

type ResetContent

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

func (ResetContent) Status

func (err ResetContent) Status() int

type SeeOther

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

func (SeeOther) Status

func (err SeeOther) Status() int

type Server

type Server struct {
	http.Server
}

Server is an http.Server with better defaults.

func NewServer

func NewServer(addr string, handler http.Handler) *Server

NewServer returns an http.Server with better defaults.

func (*Server) CA

func (s *Server) CA(ca string) error

func (*Server) TLS

func (s *Server) TLS(cert, key string) error

type ServiceUnavailable

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

func (ServiceUnavailable) Status

func (err ServiceUnavailable) Status() int

type SwitchingProtocols

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

func (SwitchingProtocols) Status

func (err SwitchingProtocols) Status() int

type Teapot

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

func (Teapot) Status

func (err Teapot) Status() int

type TemporaryRedirect

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

func (TemporaryRedirect) Status

func (err TemporaryRedirect) Status() int

type Timer

type Timer struct {
	metrics.Timer
	// contains filtered or unexported fields
}

Timer is an http.Handler that counts requests via go-metrics.

func Timed

func Timed(handler http.Handler, name string, registry metrics.Registry) *Timer

Timed returns an http.Handler that starts a timer, passes requests to an underlying http.Handler, stops the timer, and updates the timer via go-metrics.

func (*Timer) ServeHTTP

func (t *Timer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP starts a timer, passes the request to the underlying http.Handler, stops the timer, and updates the timer 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

func (mux *TrieServeMux) Handler(r *http.Request) (http.Handler, string)

Handler returns the handler to use for the given HTTP request and mutates the querystring to add wildcards extracted from the URL.

Yes, it's bad that this mutates the request. On the other hand, this is a relatively standard interface and is most used in testing where behavior like this can be allowed.

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 {
	// contains filtered or unexported fields
}

func (Unauthorized) Status

func (err Unauthorized) Status() int

type UnsupportedMediaType

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

func (UnsupportedMediaType) Status

func (err UnsupportedMediaType) Status() int

type UseProxy

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

func (UseProxy) Status

func (err UseProxy) Status() int

Notes

Bugs

  • currently only handles Origin and header-related CORS headers. Early indication is that logic will be required for handling certain header types (the credential-related ones in particular) so we may need to come up with something more robust than just dragging an http.Header around

Directories

Path Synopsis
Package mocking makes testing Tiger Tonic services easier.
Package mocking makes testing Tiger Tonic services easier.

Jump to

Keyboard shortcuts

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