La seule autre solution que j'ai vue, par exemple dans "Passing Context to Interface Methods" est :
créer une
structqui accepte un contexte intégré et notrehandlertype, et nous satisfaisons toujours lehttp.Handlerinterface grâce àServeHTTP.
Dans votre cas, la struct inclurait le pool , et le handler fonction.
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
}
}