{"id":13764112,"url":"https://github.com/posener/client-timing","last_synced_at":"2025-09-12T18:43:46.741Z","repository":{"id":57496987,"uuid":"122559805","full_name":"posener/client-timing","owner":"posener","description":"An HTTP client for go-server-timing middleware. Enables automatic timing propagation through HTTP calls between servers.","archived":false,"fork":false,"pushed_at":"2020-03-13T18:47:59.000Z","size":16,"stargazers_count":25,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T04:07:18.844Z","etag":null,"topics":["client","go","golang","http","http-timing","timing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posener.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-23T01:52:45.000Z","updated_at":"2025-08-02T09:27:16.000Z","dependencies_parsed_at":"2022-09-03T23:20:40.860Z","dependency_job_id":null,"html_url":"https://github.com/posener/client-timing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/posener/client-timing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fclient-timing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fclient-timing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fclient-timing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fclient-timing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posener","download_url":"https://codeload.github.com/posener/client-timing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fclient-timing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274856675,"owners_count":25362655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","go","golang","http","http-timing","timing"],"created_at":"2024-08-03T15:01:14.201Z","updated_at":"2025-09-12T18:43:46.683Z","avatar_url":"https://github.com/posener.png","language":"Go","readme":"# client-timing\n\n[![Build Status](https://travis-ci.org/posener/client-timing.svg?branch=master)](https://travis-ci.org/posener/client-timing)\n[![codecov](https://codecov.io/gh/posener/client-timing/branch/master/graph/badge.svg)](https://codecov.io/gh/posener/client-timing)\n[![GoDoc](https://godoc.org/github.com/posener/client-timing?status.svg)](http://godoc.org/github.com/posener/client-timing)\n[![Go Report Card](https://goreportcard.com/badge/github.com/posener/client-timing)](https://goreportcard.com/report/github.com/posener/client-timing)\n\nAn HTTP client for [go-server-timing](https://github.com/mitchellh/go-server-timing) middleware.\n\n## Features:\n\n* An HTTP `Client` or `RoundTripper`, fully compatible with Go's standard library.\n* Automatically time HTTP requests sent from an HTTP handler.\n* Collects all timing headers from upstream servers.\n* Customize timing headers according to the request, response and error of the HTTP round trip.\n\n## Install\n\n`go get -u github.com/posener/client-timing`\n\n## Usage\n\n1. Add a `*clienttiming.Timer` to your server handler, or create it in the handler function itself.\n2. Wrap the `http.Handler` with [`servertiming.Middleware`](https://godoc.org/github.com/mitchellh/go-server-timing#Middleware).\n2. In the handler function, having `timer` of type `*clienttiming.Timer` and `req` is the `*http.Request`:\n\n    a. Create an [`*http.Client`](https://godoc.org/net/http#Client) using `timer.Client(req.Context())`\n\n    b. Or create an [`http.RoundTripper`](https://godoc.org/net/http#RoundTripper) using `timer.Transport(req.Context())`\n\n3. Use option a or b directly or inject it to a library that accepts them, in your outgoing HTTP request\n   from the handler.\n4. That is it! the timing header will appear in the response from the handler.\n\n## Example\n\nSuppose we have an HTTP handler:\n\n```go\ntype handler struct {\n\ttimer *clienttiming.Timer\n}\n```\n\nOur usage of that handler will be:\n\n```go\nfunc main() {\n\th := \u0026handler{\n\t\ttimer: clienttiming.New(clienttiming.WithName(\"my-server\")),\n\t}\n\tlog.Fatal(http.ListenAndServe(\":8080\", servertiming.Middleware(h)))\n}\n```\n\n\n### Example for `Client` function:\n\n```go\nfunc (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {\n\t// Create an http client using the request context\n\tc := h.timer.Client(r.Context())\n\n\t// Perform HTTP requests, as many as you like\n\tresp, err := c.Get(\"https://golang.org/\")\n\n\t...\n}\n```\n\n### Example for `Transport` function:\n\n```go\nfunc (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {\n\t// Instrument an http client with a timing transport\n\tc := \u0026http.Client{\n\t\tTransport: h.timer.Transport(r.Context()),\n\t}\n\n\t// Perform HTTP requests, as many as you like\n\tresp, err := c.Get(\"https://golang.org/\")\n\n\t...\n}\n```\n\n### Run the [example](./example/main.go)\n\n`go run ./example/main.go`\n","funding_links":[],"categories":["Actual middlewares","Web Frameworks","中间件","中间件### 中间件","Web框架"],"sub_categories":["Middlewares","中间件","版本控制`版本控制相关库`","Fail injection"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fclient-timing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposener%2Fclient-timing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fclient-timing/lists"}