Aug 28, 2017 · 1 min read
Few additional alternatives:
// idea 1. flip the order of info and counter
// doesn’t help with length, but it mayremove
// interface{} in httpRequests
httpReqKey{“GET”, 404}.Inc(httpRequests)// idea 2.1. wrapper
type httpRequests struct { *prometheus.Counter }
func (http *httpRequests) Add(method string, code int) { … }// idea 2.2. wrapper
type httpRequests struct { *prometheus.Counter }
func (http *httpRequests) Add(req *httpReqKey) { … }// idea 3. counter func via reflection
addHttpRequest := func(method string, code int){}
prometheus.InitCounter(&addHttpRequest)// idea 2.2. + 3., auto type wrapper
type httpRequests struct {
*prometheus.Counter
Add func(method string, code int){}
}
…
var httpRequests httpRequests
prometheus.InitCounter(&httpRequests)
