Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rubenv/servertiming
Go library for adding Server-Timing headers to your application.
https://github.com/rubenv/servertiming
devtools go golang server-timing
Last synced: about 2 months ago
JSON representation
Go library for adding Server-Timing headers to your application.
- Host: GitHub
- URL: https://github.com/rubenv/servertiming
- Owner: rubenv
- License: mit
- Created: 2018-08-21T08:44:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-11T08:16:24.000Z (over 6 years ago)
- Last Synced: 2024-06-20T12:01:32.261Z (7 months ago)
- Topics: devtools, go, golang, server-timing
- Language: Go
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# servertiming
> Go library for adding [`Server-Timing` headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing) to your application.
[![Build Status](https://travis-ci.org/rubenv/servertiming.svg?branch=master)](https://travis-ci.org/rubenv/servertiming) [![GoDoc](https://godoc.org/github.com/rubenv/servertiming?status.png)](https://godoc.org/github.com/rubenv/servertiming)
![Timings in Chrome Dev Tools](devtools.png)
## Usage
```go
// Create a new instance:t := servertiming.New()
// Optionally enable name prefixing to preserve the order of metrics (will adjust names though!)
t.EnablePrefix()
// Add a few metrics, either by manually specifying the duration:
t.Add("cache", "Cache Read", 23200*time.Microsecond)
// Or by using the start-stop API:
ti.Start("db", "Database query")
// query db
ti.Stop("db")// Then send it with your response:
w.Header().Set("Server-Timing", ti.String())
```Note: timings can be sent as a trailer when using HTTP2, see the example in `net/http`: [Example (Trailers)](https://godoc.org/net/http#example-ResponseWriter--Trailers).
## License
This library is distributed under the [MIT](LICENSE) license.