-1

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()

1 Answers1

0

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().

Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143