I want to pass a function as a parameter in a go function. Here is my code:
func Call(path string, method func()) {
// TODO launch the method here
}
When I want to call this function, I want to do this:
func routes() {
app.Call("/", controllers.Index())
}
And the Index()
method is:
func Index(res http.ResponseWriter, req http.Request) {
userAgent := req.Header.Get("User-Agent")
fmt.Fprintf(res, "You're User-Agent is %s", userAgent)
}
Is a good idea to create a type
and pass this type
as parameter ?