I'm trying to use mux and set some handlers. I have the following handler
func homePage(w http.ResponseWriter, r *http.Request) {
// Some code
}
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", homePage)
log.Fatal(http.ListenAndServe(":8090", router))
}
Is there any way to pass more arguments to the handler function so that I can do more logic? I mean add an argument to homePage
function called message
. Something like this...
func homePage(w http.ResponseWriter, r *http.Request, message string) {
// Do some logic with message
// Rest of code
}
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", homePage("hello"))
log.Fatal(http.ListenAndServe(":8090", router))
}