Documentation ¶
Overview ¶
Package whmux provides some useful request mux helpers for demultiplexing requests to one of a number of handlers.
Index ¶
- func Exact(h http.Handler) http.Handler
- func ExactPath(h http.Handler) http.Handler
- func RequireGet(h http.Handler) http.Handler
- func RequireMethod(method string, h http.Handler) http.Handler
- func Shift(path string) (dir, left string)
- type Dir
- type Host
- type IntArg
- type Method
- type Overlay
- type StringArg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExactPath ¶
ExactPath takes an http.Handler that returns a new http.Handler that doesn't accept any more path elements and returns a 404 if more are provided.
func RequireGet ¶
RequireGet is simply RequireMethod but called with "GET" as the first argument.
func RequireMethod ¶
RequireMethod takes an http.Handler and returns a new http.Handler that only works with the given HTTP method. If a different method is used, a 405 is returned.
Types ¶
type Dir ¶
Dir is an http.Handler that mimics a directory. It mutates an incoming request's URL.Path to properly namespace handlers. This way a handler can assume it has the root of its section. If you want the original URL, use req.RequestURI (but don't modify it).
type Host ¶
Host is an http.Handler that chooses a subhandler based on the request Host header. The star host ("*") is a default handler.
type IntArg ¶
type IntArg webhelp.ContextKey
IntArg is a way to pull off numeric path elements from an incoming URL. You'll need to create one with NewIntArg.
func (IntArg) Get ¶
Get returns a stored value for the Arg from the Context and ok = true if found, or ok = false if no value was found (which won't be the case if a higher-level handler was this arg)
func (IntArg) MustGet ¶
MustGet is like Get but panics in cases when ok would be false. If used with whfatal.Catch, will return a 404 to the user.
func (IntArg) Shift ¶
Shift takes an http.Handler and returns a new http.Handler that does additional request processing. When an incoming request is processed, the new http.Handler pulls the next path element off of the incoming request path and puts the value in the current Context. It then passes processing off to the wrapped http.Handler. It responds with a 404 if no numeric value is found.
type Method ¶
Method is an http.Handler muxer that keys off of the given HTTP request method.
type Overlay ¶
Overlay is essentially a Dir that you can put in front of another http.Handler. If the requested entry isn't in the overlay Dir, the Default will be used. If no Default is specified this works exactly the same as a Dir.
type StringArg ¶
type StringArg webhelp.ContextKey
StringArg is a way to pull off arbitrary path elements from an incoming URL. You'll need to create one with NewStringArg.
func NewStringArg ¶
func NewStringArg() StringArg
func (StringArg) Get ¶
Get returns a stored value for the Arg from the Context, or "" if no value was found (which won't be the case if a higher-level handler was this arg)
func (StringArg) Shift ¶
Shift takes an http.Handler and returns a new http.Handler that does additional request processing. When an incoming request is processed, the new http.Handler pulls the next path element off of the incoming request path and puts the value in the current Context. It then passes processing off to the wrapped http.Handler. The value will be an empty string if no argument is found.