client-timing alternatives and similar packages
Based on the "Actual middlewares" category.
Alternatively, view client-timing alternatives based on common mentions on social networks and blogs.
-
go-server-timing
DISCONTINUED. Go (golang) library for creating and consuming HTTP Server-Timing headers -
ln-paywall
Go middleware for monetizing your API on a per-request basis with Bitcoin and Lightning ⚡️
SaaSHub - Software Alternatives and Reviews
Do you think we are missing an alternative of client-timing or a related project?
README
client-timing
An HTTP client for go-server-timing middleware.
Features:
- An HTTP
ClientorRoundTripper, fully compatible with Go's standard library. - Automatically time HTTP requests sent from an HTTP handler.
- Collects all timing headers from upstream servers.
- Customize timing headers according to the request, response and error of the HTTP round trip.
Install
go get -u github.com/posener/client-timing
Usage
- Add a
*clienttiming.Timerto your server handler, or create it in the handler function itself. - Wrap the
http.Handlerwithservertiming.Middleware. In the handler function, having
timerof type*clienttiming.Timerandreqis the*http.Request:a. Create an
*http.Clientusingtimer.Client(req.Context())b. Or create an
http.RoundTripperusingtimer.Transport(req.Context())Use option a or b directly or inject it to a library that accepts them, in your outgoing HTTP request from the handler.
That is it! the timing header will appear in the response from the handler.
Example
Suppose we have an HTTP handler:
type handler struct {
timer *clienttiming.Timer
}
Our usage of that handler will be:
func main() {
h := &handler{
timer: clienttiming.New(clienttiming.WithName("my-server")),
}
log.Fatal(http.ListenAndServe(":8080", servertiming.Middleware(h)))
}
Example for Client function:
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Create an http client using the request context
c := h.timer.Client(r.Context())
// Perform HTTP requests, as many as you like
resp, err := c.Get("https://golang.org/")
...
}
Example for Transport function:
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Instrument an http client with a timing transport
c := &http.Client{
Transport: h.timer.Transport(r.Context()),
}
// Perform HTTP requests, as many as you like
resp, err := c.Get("https://golang.org/")
...
}
Run the [example](./example/main.go)
go run ./example/main.go