Client and Server HTTP middleware libraries leveraging Go's
Just to clarify, these libraries are not yet another Go HTTP router, nor is it an REST client library.
They are meant to interop with anything that
net/http supports, without requiring much re-jigging of code.
The reason to include both server-side (middlewares) and client-side (tripperwares) is because Go HTTP servers often make HTTP requests themselves when handling an inbound request. As such, in order to make services debuggable in production, it is crucial to have the same sort of monitoring, logging and tracing available for both inbound and outbound requests. Moreover, some values (tracing, auth tokens) need to be passed from input to the output.
These libraries are meant as excellent companions for interceptors of
github.com/grpc-ecosystem/go-grpc-middleware making it easy to build combined gRPC/HTTP Golang servers.
Middlewares adhere to
func (http.Handler) http.Handler signature. I.e. it is a handler that accept a handler.
This means that the composition purely
net/http-based. This means that you can use it with
or a home-grown router/framework of choice, worst-case you'll slide it between the
http.Server and the
http.Handler function of the framework.
As such, this repository focuses on debugability of handlers. The crucial package here is
which propagates a set of key-value pairs through different middlewares in the
http.Request.Context for both writing and reading.
This means you get a canonical set of metadata for logging, monitoring and tracing of your inbound requests. Additionally, it
allows assigning a name to a group of handlers (e.g.
auth), and names to individual handlers (e.g.
The middlewares provided in this repo are:
Tripperwares adhere to
func (http.RoundTripper) http.RoundTripper signature, hence the name. As such they are used as
http.Client, and can wrap other transports.
This means that the composition is purely
net/http-based. Since there are few (if any) libraries for this, the repository
will have multiple useful libraries for making external calls.
The crucial package here is again
http_ctxtags(tags/README.md) as it introduces a concept of a service name. This is
either user-specified or automatically detected from the URL (for external calls), and is used as a key indicator in all
other debugability handlers.
The tripperwares provided in this repo are:
/debug/requestpage for client-side HTTP request debugging, allowing you to inspect failed requests, outbound headers, payload sizes etc etc.
All the libraries included here are meant to be minimum-dependency based. As such the root of the package,
contains helper libraries that allow for chaining and wrapping
http.ResponseWriter objects. See documentation for more.
This code is experimental and still considered a work in progress. It is meant to be the underpinnings of the Go HTTP stack at Improbable.
Additional tooling will be added, and contributions are welcome.
go-httpwares is released under the Apache 2.0 license. See the LICENSE file for details.