https://github.com/luckytea/httpclient
Simple golang package with fasthttp client and prometheus metric.
https://github.com/luckytea/httpclient
fasthttp golang metrics prometheus
Last synced: 3 months ago
JSON representation
Simple golang package with fasthttp client and prometheus metric.
- Host: GitHub
- URL: https://github.com/luckytea/httpclient
- Owner: luckytea
- License: mit
- Created: 2021-03-11T13:41:36.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-08-25T12:41:20.000Z (almost 3 years ago)
- Last Synced: 2026-01-14T21:34:14.845Z (5 months ago)
- Topics: fasthttp, golang, metrics, prometheus
- Language: Go
- Homepage:
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http-client
Simple golang package with fasthttp client and prometheus metric.
## Example NewWithMetric
```go
// metric
var netSourcesLatencyHistogram = func() *prometheus.HistogramVec {
var metric = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "service",
Subsystem: "net",
Name: "sources_latency",
Help: "Third party response latency histogram.",
Buckets: prometheus.ExponentialBuckets(0.05, 2, 8),
}, []string{"source"})
prometheus.MustRegister(metric)
return metric
}()
// create
client := httpclient.NewWithMetric("domain", netSourcesLatencyHistogram)
// request
if err := p.client.DoTimeout(req, resp); err != nil {
// error handling
}
```
## Example NewWithMetricFunc
```golang
// metric func
var latencyFunc = func(start time.Time, domain string) {
latencyMetric.WithLabelValues(domain).Observe(float64(time.Since(start).Nanoseconds()) / 1000000)
}
// func
client := httpclient.NewWithMetricFunc("domain", latencyFunc)
// request
if err := p.client.DoTimeout(req, resp); err != nil {
// error handling
}
```