Documentation
¶
Overview ¶
Package http includes handlers and utilties.
Index ¶
- func GetAndReplaceBody(req *http.Request, w io.Writer) error
- func GetAndReplaceBodyBytes(req *http.Request) ([]byte, error)
- func NewJSONVersionHandler(version string) http.HandlerFunc
- func NewSimpleBasicAuthHandler(next http.Handler, username, password, realm string) http.HandlerFunc
- type MWMux
- type Mux
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAndReplaceBody ¶ added in v0.5.0
GetAndReplaceBody writes the body of req to w. If needed the body is replaced with a byte buffer for re-use.
func GetAndReplaceBodyBytes ¶ added in v0.5.0
GetAndReplaceBodyBytes returns the body of req as a byte slice. If needed the body is replaced with a byte buffer for re-use.
Example ¶
buf := bytes.NewBuffer([]byte("Hello, world!"))
req, err := http.NewRequestWithContext(context.Background(), "GET", "", buf)
if err != nil {
log.Fatal(err)
}
ret, err := GetAndReplaceBodyBytes(req)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(ret))
Output: Hello, world!
func NewJSONVersionHandler ¶ added in v0.3.0
func NewJSONVersionHandler(version string) http.HandlerFunc
NewJSONVersionHandler responds with JSON from version. The JSON is in the form of `{"version":"v0.0.1"}`. No validation is done on version; it should conform to a JSON string.
func NewSimpleBasicAuthHandler ¶ added in v0.3.0
func NewSimpleBasicAuthHandler(next http.Handler, username, password, realm string) http.HandlerFunc
NewSimpleBasicAuthHandler is an HTTP Basic authentication middleware. The returned handler verifies the the correct authentication against username and password before handing off to next, or reponds with an HTTP 401 setting the WWW-Authenticate header using realm.
Types ¶
type MWMux ¶ added in v0.4.0
type MWMux struct {
// contains filtered or unexported fields
}
MWMux applies middleware when registering HTTP handlers.
func (*MWMux) Handle ¶ added in v0.4.0
Handle layers middlewares around handler and registers them with pattern.
func (*MWMux) HandleFunc ¶ added in v0.4.0
HandleFunc layers middlewares around handler and registers them with pattern.