L'unica altra soluzione che ho visto, ad esempio in "Passing Context to Interface Methods" è:
crea una struct che accetta un contesto incorporato e il nostro handler digita e soddisfiamo ancora il http.Handler interfaccia grazie a ServeHTTP .
Nel tuo caso, la struct includerebbe il pool e il handler funzione.
type appContext struct {
pool Pool
}
type appHandler struct {
*appContext
h func(a *appContext, w http.ResponseWriter, r *http.Request) (int, error)
}
func (ah appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
}
func main() {
context := &appContext{
pool: ...,
// any other data
}
}