我有这个productHandler:funcproductHandler(whttp.ResponseWriter,r*http.Request){varpropcontroller.Productswitchr.Method{case"GET":prop.All()}[etc..]}然后我注册我的productHandlerhttp.HandleFunc("/products/",productHandler)如何将以下中间件添加到HTTP请求中?funcAccept(nexthttp.Handler)http.Handler{fc:=func(whttp.ResponseWrit
我正在使用gorilla多路复用器来获取模式值。我如何像这样处理一个空变量:开始:funcProductHandler(whttp.ResponseWriter,r*http.Request){vars:=mux.Vars(r)a:=vars["key"]ifa=""{//doesnotseemtoregisteremptystring//dosomething}else//dosomething}varr=mux.NewRouter()funcmain(){r.HandleFunc("/products/{key}",ProductHandler)http.Handle("/",r)
我正在使用gorilla多路复用器来获取模式值。我如何像这样处理一个空变量:开始:funcProductHandler(whttp.ResponseWriter,r*http.Request){vars:=mux.Vars(r)a:=vars["key"]ifa=""{//doesnotseemtoregisteremptystring//dosomething}else//dosomething}varr=mux.NewRouter()funcmain(){r.HandleFunc("/products/{key}",ProductHandler)http.Handle("/",r)