La única otra solución que he visto, por ejemplo, en "Pasar contexto a métodos de interfaz" es:
crear una struct
que acepta un contexto incrustado y nuestro handler
tipo, y todavía satisfacemos el http.Handler
interfaz gracias a ServeHTTP
.
En tu caso, la struct
incluiría el pool
, y el handler
función.
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
}
}