本文整理匯總了Golang中github.com/gorilla/mux.Router.Handle方法的典型用法代碼示例。如果您正苦於以下問題:Golang Router.Handle方法的具體用法?Golang Router.Handle怎麽用?Golang Router.Handle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gorilla/mux.Router
的用法示例。
在下文中一共展示了Router.Handle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InitPost
func InitPost(r *mux.Router) {
l4g.Debug("Initializing post api routes")
r.Handle("/posts/{post_id}", negroni.New(
negroni.HandlerFunc(RequireAuth),
negroni.HandlerFunc(getPost),
)).Methods("GET")
sr := r.PathPrefix("/channels/{id}").Subrouter()
sr.Handle("/create", negroni.New(
negroni.HandlerFunc(RequireAuth),
negroni.HandlerFunc(createPost),
)).Methods("POST")
sr.Handle("/update", negroni.New(
negroni.HandlerFunc(RequireAuth),
negroni.HandlerFunc(updatePost),
)).Methods("POST")
// {offset:[0-9]+}/{limit:[0-9]+}
sr.Handle("/posts/", negroni.New(
negroni.HandlerFunc(RequireAuth),
negroni.HandlerFunc(getPosts),
)).Methods("GET")
}
示例2: setupRouters
func setupRouters(router *mux.Router, parentMiddleWare []http.HandlerFunc, routers []*Router) {
if len(routers) == 0 {
return
}
for _, rd := range routers {
combinedMiddleWareHandlers := []http.HandlerFunc{}
combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, parentMiddleWare...)
combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, rd.middlewares...)
panicOnZeroMethods := len(rd.subRouters) == 0 //Panic if we have no controller methods and also no subrouters
for method, handler := range GetControllerMethods(rd.controller, panicOnZeroMethods) {
for _, urlPart := range rd.urlParts {
muxRoute := router.Handle(urlPart, newNegroniMiddleware(combinedMiddleWareHandlers, handler))
muxRoute.Methods(method)
}
}
if len(rd.urlParts) == 0 {
setupRouters(router, combinedMiddleWareHandlers, rd.subRouters)
continue
}
for _, urlPart := range rd.urlParts {
var subRouterToUse *mux.Router
if urlPart != "" {
subRouterToUse = router.PathPrefix(urlPart).Subrouter()
} else {
subRouterToUse = router
}
setupRouters(subRouterToUse, combinedMiddleWareHandlers, rd.subRouters)
}
}
}
示例3: staticFileRouter
func staticFileRouter(r *mux.Router) *mux.Router {
// static
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/",
myFileHandler{http.FileServer(http.Dir(*staticPath))}))
// bootstrap ui insists on loading templates from this path
r.PathPrefix("/template/").Handler(http.StripPrefix("/template/",
myFileHandler{http.FileServer(http.Dir(*staticPath))}))
// application pages
appPages := []string{
"/overview",
"/search",
"/indexes",
"/analysis",
"/monitor",
}
for _, p := range appPages {
// if you try to use index.html it will redirect...poorly
r.PathPrefix(p).Handler(RewriteURL("/",
http.FileServer(http.Dir(*staticPath))))
}
r.Handle("/", http.RedirectHandler("/static/index.html", 302))
return r
}
示例4: fileServeRoutes
func fileServeRoutes(router *mux.Router) {
controller := controllers.NewFileServeController()
router.Handle("/image/{folder}/{file}", negroni.New(
negroni.HandlerFunc(controller.GetImage),
)).Methods("GET")
}
示例5: homeRoutes
func homeRoutes(router *mux.Router) {
controller := controllers.NewHomeController()
router.Handle("/", negroni.New(
negroni.HandlerFunc(controller.Home),
)).Methods("GET")
}
示例6: authRoutes
func authRoutes(router *mux.Router) {
controller := controllers.NewAuthController()
router.Handle("/login", negroni.New(
negroni.HandlerFunc(controller.Login),
)).Methods("POST")
}
示例7: Routing
// Routing ... list of routing services
func (c AccountRouter) Routing(router *mux.Router, apiprefix string) {
baseModel := base.BaseModel{Status: "ACTIVE", CreatedAt: time.Now()}
httpUtilFunc := utilFunc.HTTPUtilityFunctions{}
account := controllers.AccountController{c.DataStore, baseModel, httpUtilFunc}
router.Handle(apiprefix+"/accounts",
negroni.New(
negroni.HandlerFunc(authentication.RequireTokenAuthentication),
negroni.HandlerFunc(account.CreateAccount),
)).Methods("POST")
router.Handle(apiprefix+"/account/categories",
negroni.New(
negroni.HandlerFunc(authentication.RequireTokenAuthentication),
negroni.HandlerFunc(account.CreateAccount),
)).Methods("POST")
router.Handle(apiprefix+"/account/fundsource",
negroni.New(
negroni.HandlerFunc(authentication.RequireTokenAuthentication),
negroni.HandlerFunc(account.CreateAccountCategory),
)).Methods("POST")
router.Handle(apiprefix+"/account/limit",
negroni.New(
negroni.HandlerFunc(authentication.RequireTokenAuthentication),
negroni.HandlerFunc(account.CreateAccountLimit),
)).Methods("POST")
router.Handle(apiprefix+"/account/funding",
negroni.New(
negroni.HandlerFunc(authentication.RequireTokenAuthentication),
negroni.HandlerFunc(account.CreateAccountFundMapping),
)).Methods("POST")
}
示例8: setupRouters
func setupRouters(ctx *RouterContext.RouterContext, router *mux.Router, parentMiddleWare []HttpHandlerFunc, routeDefinitions []*RouteDefinition) {
if len(routeDefinitions) == 0 {
return
}
for _, rh := range routeDefinitions {
var routerToUse *mux.Router
if rh.prefix != "" {
routerToUse = router.PathPrefix(rh.prefix).Subrouter()
} else {
routerToUse = router
}
combinedMiddleWareHandlers := []HttpHandlerFunc{}
combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, parentMiddleWare...)
combinedMiddleWareHandlers = append(combinedMiddleWareHandlers, rh.middlewares...)
for _, singleRouteDefinition := range rh.routeDefinitions {
for method, h := range GetIRouteControllers(singleRouteDefinition) {
muxRoute := routerToUse.Handle(singleRouteDefinition.GetPathPart(), newNegroniMiddleware(ctx, combinedMiddleWareHandlers, h))
muxRoute.Methods(method)
}
}
setupRouters(ctx, routerToUse, combinedMiddleWareHandlers, rh.subRoutes)
}
}
示例9: setupMuxHandlers
func (me *endPoint) setupMuxHandlers(mux *mux.Router) {
fn := handleIncoming(me)
m := interpose.New()
for i, _ := range me.modules {
m.Use(me.modules[i])
//fmt.Println("using module:", me.modules[i], reflect.TypeOf(me.modules[i]))
}
m.UseHandler(http.HandlerFunc(fn))
if me.info.Version == "*" {
mux.Handle(me.muxUrl, m).Methods(me.httpMethod)
} else {
urlWithVersion := cleanUrl(me.info.Prefix, "v"+me.info.Version, me.muxUrl)
urlWithoutVersion := cleanUrl(me.info.Prefix, me.muxUrl)
// versioned url
mux.Handle(urlWithVersion, m).Methods(me.httpMethod)
// content type (style1)
header1 := fmt.Sprintf("application/%s-v%s+json", me.info.Vendor, me.info.Version)
mux.Handle(urlWithoutVersion, m).Methods(me.httpMethod).Headers("Accept", header1)
// content type (style2)
header2 := fmt.Sprintf("application/%s+json;version=%s", me.info.Vendor, me.info.Version)
mux.Handle(urlWithoutVersion, m).Methods(me.httpMethod).Headers("Accept", header2)
}
}
示例10: EventListenerRoutes
func EventListenerRoutes(router *mux.Router) *mux.Router {
router.Handle("/event",
negroni.New(
negroni.HandlerFunc(controllers.EventController),
)).Methods("POST")
return router
}
示例11: QueryRoutes
func QueryRoutes(router *mux.Router) *mux.Router {
router.Handle("/query",
negroni.New(
negroni.HandlerFunc(controllers.QueryController),
)).Methods("POST")
return router
}
示例12: addRoutes
// Adds defaults routes, ping and status.
func addRoutes(r *mux.Router) {
ping := handlers.RecoveryFunc(handlers.Ping)
time := handlers.RecoveryFunc(handlers.Time)
status := handlers.RecoveryFunc(handlers.Status)
r.Handle("/status/", status).Methods("GET")
r.Handle("/ping/", ping).Methods("GET")
r.Handle("/time/", time).Methods("GET")
}
示例13: InitWebSocket
func InitWebSocket(r *mux.Router) {
l4g.Debug("Initializing websocket api")
r.Handle("/websocket/{uuid}", negroni.New(
negroni.HandlerFunc(RequireAuthAndUser),
negroni.HandlerFunc(connect),
)).Methods("GET")
hub.Start()
}
示例14: SetOfferingRoutes
func SetOfferingRoutes(router *mux.Router) *mux.Router {
router.Handle("/offering",
negroni.New(
negroni.HandlerFunc(authentication.RequireTokenAuthentication),
negroni.HandlerFunc(controllers.OfferingListController),
)).Methods("GET")
return router
}
示例15: SetHelloRoutes
func SetHelloRoutes(router *mux.Router) *mux.Router {
router.Handle("/test/check",
negroni.New(
negroni.HandlerFunc(authentication.RequireTokenAuthentication),
negroni.HandlerFunc(controllers.HelloController),
)).Methods("GET")
return router
}