ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - posener/client-timing: An HTTP client for go-server-timing middleware. Enables automatic timing propagation through HTTP calls between servers.
An HTTP client for go-server-timing middleware. Enables automatic timing propagation through HTTP calls between servers. - posener/client-timing
Visit Site

GitHub - posener/client-timing: An HTTP client for go-server-timing middleware. Enables automatic timing propagation through HTTP calls between servers.

GitHub - posener/client-timing: An HTTP client for go-server-timing middleware. Enables automatic timing propagation through HTTP calls between servers.

client-timing

Build Status codecov GoDoc Go Report Card

An HTTP client for go-server-timing middleware.

Features:

  • An HTTP Client or RoundTripper, 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

  1. Add a *clienttiming.Timer to your server handler, or create it in the handler function itself.

  2. Wrap the http.Handler with servertiming.Middleware.

  3. In the handler function, having timer of type *clienttiming.Timer and req is the *http.Request:

    a. Create an *http.Client using timer.Client(req.Context())

    b. Or create an http.RoundTripper using timer.Transport(req.Context())

  4. Use option a or b directly or inject it to a library that accepts them, in your outgoing HTTP request from the handler.

  5. 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

go run ./example/main.go

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory