I want to set a value in mux.Vars()
with MatcherFunc
return true, then handlerFun
can access to read. But panic assignment to entry in nil map when mux.Vars(request)["key"] = "value"
How can I set a value:
domainRouter := router.MatcherFunc(func(request *http.Request, match *mux.RouteMatch) bool {
if isOk {
mux.Vars(request)["key"] = "value"
return true
}
return false
}).Subrouter()
This part of code is correct, the issue is in the place where you create mux.NewRouter()
, it seems like your domainRouter
is called before mux.NewRouter()
.