Go 1.7 includes the context
package in the standard library, and the net/http
package includes a Context
in the http.Request
structure. If you are targeting Go 1.7 and later, there is significantly less need for a package like httpctx
.
The httpctx
package provides a convenient way to handle HTTP requests
using "context-aware" handler functions. Context-aware handlers
are different from the standard http.Handler
in two important ways:
- They accept an additional parameter of the (almost) standard type
context.Context
(golang.org/x/net/context); and - They return an error result.
The httpctx
package also implements a simple middleware chaining mechanism. The idea
for this comes from Justinas Stankevičius and his alice
package. (https://github.com/justinas/alice).
For usage examples, refer to the GoDoc documentation.