Documentation ¶
Overview ¶
package httpx provides an extra layer of convenience over package http.
Index ¶
- func NotFound(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- func RequestID(ctx context.Context) string
- func Vars(ctx context.Context) map[string]string
- func WithRequestID(ctx context.Context, requestID string) context.Context
- func WithVars(ctx context.Context, vars map[string]string) context.Context
- type Handler
- type HandlerFunc
- type Router
- func (r *Router) Handle(method, path string, h Handler)
- func (r *Router) Handler(req *http.Request) (h Handler, vars map[string]string)
- func (r *Router) Header(key, value string, h Handler)
- func (r *Router) Match(f func(*http.Request) bool, h Handler)
- func (r *Router) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, req *http.Request) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithRequestID ¶
WithRequestID inserts a RequestID into the context.
Types ¶
type Handler ¶
type Handler interface {
ServeHTTPContext(context.Context, http.ResponseWriter, *http.Request) error
}
Handler is represents a Handler that can take a context.Context as the first argument.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as httpx handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
func (HandlerFunc) ServeHTTPContext ¶
func (f HandlerFunc) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error
ServeHTTPContext calls f(ctx, w, r)
type Router ¶
type Router struct { // NotFoundHandler is a Handler that will be called when a route is not // found. NotFoundHandler Handler // contains filtered or unexported fields }
Router is an httpx.Handler router.
func (*Router) Handle ¶
Handle adds a new router that routes requests using the method verb against path to the given Handler.
func (*Router) Handler ¶
Handler returns a Handler that can be used to serve the request. Most of this is pulled from http://goo.gl/tyxad8.
func (*Router) ServeHTTPContext ¶
func (r *Router) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, req *http.Request) error
ServeHTTPContext implements the Handler interface.