最佳答案
我想添加一个方便的 util 方法到 gorilla/mux
路由和路由器类型:
package util
import(
"net/http"
"github.com/0xor1/gorillaseed/src/server/lib/mux"
)
func (r *mux.Route) Subroute(tpl string, h http.Handler) *mux.Route{
return r.PathPrefix("/" + tpl).Subrouter().PathPrefix("/").Handler(h)
}
func (r *mux.Router) Subroute(tpl string, h http.Handler) *mux.Route{
return r.PathPrefix("/" + tpl).Subrouter().PathPrefix("/").Handler(h)
}
但是编译器告诉我
无法在非本地类型 mux.Router 上定义新方法
那我该怎么做呢?是否创建一个具有匿名 mux 的新结构类型。路线和音乐。路由器?还是别的什么?