# README
http-client
Simple golang package with fasthttp client and prometheus metric.
Example NewWithMetric
// 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
// 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
}
# Functions
New - return new http client with given params & backoff.
NewBackoff - return function for new backoff calculation.
NewDefault - return new http client with default params & backoff.
NewWithMetric - return new http client with default params & backoff.
NewWithMetricFunc - return new http client with default params & backoff.
# Constants
DefaultRetry - количество ретраев под текущую реализацию переключения между основными api и failover.
DefaultTimeout - стандартное время ожидания ответа от сервера.