本文整理汇总了Golang中github.com/zenazn/goji/web.Mux.Put方法的典型用法代码示例。如果您正苦于以下问题:Golang Mux.Put方法的具体用法?Golang Mux.Put怎么用?Golang Mux.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zenazn/goji/web.Mux
的用法示例。
在下文中一共展示了Mux.Put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Generate
func (rm *RouterMold) Generate() *web.Mux {
var mux *web.Mux
if rm.SubRoutes == "" {
mux = goji.DefaultMux
mux.Abandon(middleware.Logger)
} else {
mux := web.New()
mux.Use(middleware.RequestID)
mux.Use(middleware.Recoverer)
mux.Use(middleware.AutomaticOptions)
goji.Handle(rm.SubRoutes, mux)
}
for _, m := range rm.Middlewares {
mux.Use(m.MiddlewareFunc())
}
var handlerFunc func(Route) interface{}
if rm.HandlerFunc == nil {
handlerFunc = func(r Route) interface{} {
return r.Handler
}
} else {
handlerFunc = rm.HandlerFunc
}
for _, r := range rm.Routes {
var pattern interface{}
if r.RegExp != "" {
pattern = regexp.MustCompile(r.RegExp)
} else {
pattern = r.Path
}
switch r.Method {
case "HEAD":
mux.Head(pattern, handlerFunc(r))
case "GET":
mux.Get(pattern, handlerFunc(r))
case "POST":
mux.Post(pattern, handlerFunc(r))
case "PUT":
mux.Put(pattern, handlerFunc(r))
case "PATCH":
mux.Patch(pattern, handlerFunc(r))
case "DELETE":
mux.Delete(pattern, handlerFunc(r))
}
}
return mux
}
示例2: getHandler
// attach r.Handler and r.Method to the correct verb function
func getHandler(wm *web.Mux, r *Route) error {
switch strings.ToLower(r.Method) {
case "get":
wm.Get(r.Pattern, r.Handler)
case "post":
wm.Post(r.Pattern, r.Handler)
case "put":
wm.Put(r.Pattern, r.Handler)
case "patch":
wm.Patch(r.Pattern, r.Handler)
case "delete":
wm.Delete(r.Pattern, r.Handler)
default:
return errors.New("unsupported method: " + r.Method)
}
return nil
}