Egon Elbre
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)
)
    Egon Elbre

    Written by

    https://www.buymeacoffee.com/egon

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade