4 ms·
I just use a closure. So instead of defining a handler as: func HandleX(w http.ResponseWriter, req *http.Request) { // code } I use: func HandleX(s
by angra_mainyu 3y ago
I just use a closure. So instead of defining a handler as:
func HandleX(w http.ResponseWriter, req *http.Request) {
// code
}
I use:
func HandleX(store *DataStore, dep1 Foo, dep2 Bar, commonDep Common) http.HandlerFunc {
//
// maybe some initialization
//
return func(w http.ResponseWriter, req *http.Request) {
// code
}
}
and initialize them all once in whatever entrypoint there is.