本文整理匯總了Golang中github.com/gorilla/mux.Route.Methods方法的典型用法代碼示例。如果您正苦於以下問題:Golang Route.Methods方法的具體用法?Golang Route.Methods怎麽用?Golang Route.Methods使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gorilla/mux.Route
的用法示例。
在下文中一共展示了Route.Methods方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handle
func (w *Web) handle(method, urlpath string, fn Handler, midwares *MiddlewaresManager) {
var h *handler
h = newHandler(fn, midwares, w.responser, w.logger)
// match prefix
var prefix bool
if strings.HasSuffix(urlpath, "*") {
urlpath = strings.TrimSuffix(urlpath, "*")
prefix = true
}
// register mux route
var rt *mux.Route
if prefix {
rt = w.mux.PathPrefix(urlpath).Handler(h)
} else {
rt = w.mux.Handle(urlpath, h)
}
rt.Methods(strings.ToUpper(method))
// add to map
url := methodUrl(method, urlpath)
_, ok := w.handlers[url]
if ok {
panic("url conflict: " + url)
}
w.handlers[url] = h
return
}
示例2: Handler
// HANDLER create route using GorwardRouter values
func (r GowardRouter) Handler(handler http.Handler) Router {
var route *mux.Route
if r.FMiddleware != nil {
handler = bindMiddlewares(handler, r.FMiddleware...)
}
if r.FPath == "/" && r.FParentRouter != nil {
route = r.FParentRouter.NewRoute()
route = route.Path(r.FPrefix)
} else {
route = r.FRouter.NewRoute()
route.Path(r.FPath)
}
if r.FHost != "" {
route = route.Host(r.FHost)
}
if r.Methods != nil {
route = route.Methods(r.FMethods...)
}
route.Handler(handler)
return r
}
示例3: SetRoute
func (m Match) SetRoute(r *mux.Route) *mux.Route {
if m.Prefix != "" {
r = r.PathPrefix(m.Prefix)
}
if m.Hosts != nil && len(m.Hosts) > 0 {
for _, host := range m.Hosts {
r = r.Host(host)
}
}
if m.Methods != nil && len(m.Methods) > 0 {
r = r.Methods(m.Methods...)
}
if m.Schemes != nil && len(m.Schemes) > 0 {
for _, scheme := range m.Schemes {
r = r.Schemes(scheme)
}
}
if m.Queries != nil && len(m.Queries) > 0 {
for _, m := range m.Queries {
for k, v := range m {
r = r.Queries(k, v)
}
}
}
if m.Headers != nil && len(m.Headers) > 0 {
for _, m := range m.Headers {
for k, v := range m {
r = r.Headers(k, v)
}
}
}
if m.Custom != nil && len(m.Custom) > 0 {
// lookup custom function by name
// func(r *http.Request, rm *RouteMatch) bool
}
return r
}