I really like Mat Ryer's work, and I've applied most of the ideas in the 2018 version of this article to all of my Go projects since then. The one weak spot for me is this aspect: > NewServer is a big constructor that takes in all dependencies as arguments... In test cases that don’t need all of the dependencies, I pass in nil as a signal that it won’t be used. This has always felt wrong to me, but I've never been ab…
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.