You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current function/interface needs a rework. Found a Golang Uk YouTube video (Golang UK Conference 2016 - Mat Ryer - Idiomatic Go Tricks, go to 8:20 function type alternatives for single method interfaces) that discusses this which I think can be well utilised here:
http.Handler has a counterpart called http.HandlerFunc
// in net.httptypeHandlerinterface {
ServeHTTP(ResponseWriter, *Request)
}
// The HanderFUnc type is an adapter to allow the use of ordinary functions// as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is// a Handler that calls ftypeHandlerFuncfunc(ResponseWriter, *Request)
// ServerHTTP calls f(w,r)func (fHandlerFunc) ServeHTTP(wResponseWriter, r*Request) {
f(w, r)
}
this is intriguing and a technique I've not discovered before (defining a method on a function)
func type with matching signature
Method on that func implementing the interface
Method just calls the func
Now you don't even need a struct, you can just use a function
this pattern can be used when you have single method interfaces
The text was updated successfully, but these errors were encountered:
The current function/interface needs a rework. Found a Golang Uk YouTube video (Golang UK Conference 2016 - Mat Ryer - Idiomatic Go Tricks, go to 8:20 function type alternatives for single method interfaces) that discusses this which I think can be well utilised here:
http.Handler has a counterpart called http.HandlerFunc
this is intriguing and a technique I've not discovered before (defining a method on a function)
The text was updated successfully, but these errors were encountered: