Skip to content

Simple golang package with fasthttp client and prometheus metric.

License

Notifications You must be signed in to change notification settings

luckytea/httpclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

Simple golang package with fasthttp client and prometheus metric.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages