Documentation ¶
Overview ¶
Package httpx provides convenience extensions to net/http, enabling a certain style of web programming which resembles the implementation of recursive descent parsers.
Index ¶
- func Path(req *http.Request) string
- func RequestID(req *http.Request) string
- func RequestLogger(base *log.Logger, req *http.Request) *log.Logger
- func Shift(req *http.Request) string
- func WithPath(req *http.Request) *http.Request
- func WithRequestID(req *http.Request, id string) *http.Request
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Path ¶
Path returns the original URL.Path associated with req. If the context associated with req does not store a path, Path returns the empty string.
func RequestID ¶ added in v0.2.0
RequestID returns the identifier associated with the request.
func RequestLogger ¶ added in v0.2.0
RequestLogger returns a logger scoped to the specified request. The logger records the "method", "path", "remote_addr" and "user_agent" keys. If present, it also records the "request_id" key.
func Shift ¶
Shift shifts req.URL.Path forward by one segment, and returns the segment, if any. req.URL.Path must either be empty, or have a "/" prefix.
For the paths "" and "/", Shift is a no-op and returns "".
For the path "/abc", Shift sets req.URL.Path to "" and returns "abc".
For the path "/abc/anything", Shift sets req.URL.Path to "/anything", and returns "abc".
func WithPath ¶
WithPath stores req.URL.Path in the context associated with req, and returns the new *http.Request, with the updated context.
The value can later be retrieved by calling Path on the request.
If the request context stores a path already, WithPath is a no-op and returns req.
Types ¶
type Summary ¶ added in v0.2.0
type Summary struct { // Status is the first HTTP status code written, or http.StatusOK // if no status was written explicitly. Status int // Duration measures the duration of the request. Duration time.Duration // Written typically counts the number of bytes written to the HTTP // response body. Written int64 }
Summary is a summary of an HTTP server response.
func ServeInstrumented ¶ added in v0.2.0
ServeInstrumented instruments w, wraps h, and calls the wrapped handler with the instrumented http.ResponseWriter and the specified *http.Request. It returns a summary of the request.