本文整理汇总了Golang中github.com/zenazn/goji/web.Mux.Use方法的典型用法代码示例。如果您正苦于以下问题:Golang Mux.Use方法的具体用法?Golang Mux.Use怎么用?Golang Mux.Use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zenazn/goji/web.Mux
的用法示例。
在下文中一共展示了Mux.Use方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Add
func Add(mux *web.Mux) {
/* Endpoint to handler config */
mux.Get("/", home)
mux.Get("/home", about)
mux.Use(mux.Router)
}
示例2: rooter
func rooter(m *web.Mux) http.Handler {
m.Use(SuperSecure)
m.Get("/index", UserRoot)
m.Get("/user/index", UserIndex)
m.Get("/user/new", UserNew)
m.Post("/user/new", UserCreate)
m.Get("/user/edit/:id", UserEdit)
m.Post("/user/update/:id", UserUpdate)
m.Get("/user/delete/:id", UserDelete)
return m
}
示例3: route
func route(m *web.Mux) {
// Add routes to the global handler
setGetHandler(m, "/", Root)
// Use Sinatra-style patterns in your URLs
setGetHandler(m, "/novel/:ncode", responseCache(getNovelInfo))
setGetHandler(m, "/novel_content/:ncode/:sublist_id", responseCache(getNovelContent))
// Middleware can be used to inject behavior into your app. The
// middleware for this application are defined in middleware.go, but you
// can put them wherever you like.
m.Use(Json)
}
示例4: rooter
func rooter(m *web.Mux) http.Handler {
m.Use(SuperSecure)
user := web.New()
goji.Handle("/user/*", user)
user.Use(middleware.SubRouter)
user.Get("/index", UserIndex)
user.Get("/new", UserNew)
user.Post("/new", UserCreate)
user.Get("/edit/:id", UserEdit)
user.Post("/update/:id", UserUpdate)
user.Get("/delete/:id", UserDelete)
return m
}
示例5: 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
}
示例6:
// This demo file shows two ways to test the handlers, it is not suggested to use both in a real
// project, the two methods are provided here as a sample.
// Tests that simply create a mux and exercise that by calling the Mux's ServeHTTP function
// This is great for isolated tests, it becomes difficult when the middleware higher in the stack
// is needed or other concurrent goroutines and other handlers al also needed for higher-level tests
var _ = Describe("Mux-based settings tests", func() {
var mx *web.Mux // mux with the handlers we're testing
BeforeEach(func() {
settings = make(map[string]string)
mx = NewMux()
gojiutil.AddCommon15(mx, log15.Root())
mx.Use(gojiutil.ParamsLogger(true)) // useful for troubleshooting
})
It("gets what it sets", func() {
// set a value
req, _ := http.NewRequest("PUT", "http://example.com/settings/hello?value=world",
bytes.NewReader([]byte{}))
resp := httptest.NewRecorder()
mx.ServeHTTP(resp, req)
Ω(resp.Code).Should(Equal(200))
Ω(settings["hello"]).Should(Equal("world"))
// get the value back
req, _ = http.NewRequest("GET", "http://example.com/settings/hello", nil)
resp = httptest.NewRecorder()
mx.ServeHTTP(resp, req)