उदाहरण के लिए "इंटरफ़ेस विधियों के संदर्भ में पासिंग" में मैंने देखा है कि एकमात्र अन्य समाधान है:
<ब्लॉकक्वॉट>
एक struct बनाएं जो एक एम्बेडेड संदर्भ और हमारे handler . को स्वीकार करता है टाइप करें, और हम अभी भी http.Handler . को संतुष्ट करते हैं इंटरफ़ेस ServeHTTP . के लिए धन्यवाद ।
आपके मामले में, struct इसमें pool शामिल होगा , और handler समारोह।
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
}
}