本文整理匯總了Golang中github.com/gorilla/mux.Router.Path方法的典型用法代碼示例。如果您正苦於以下問題:Golang Router.Path方法的具體用法?Golang Router.Path怎麽用?Golang Router.Path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gorilla/mux.Router
的用法示例。
在下文中一共展示了Router.Path方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UIRouter
// Router adds panel routes to an existing mux.Router.
func UIRouter(theBaseHref string, rt *mux.Router) *mux.Router {
baseHref = theBaseHref
rt.Path("/calls").Methods("GET").HandlerFunc(uiCalls).Name(appmonUICalls)
rt.Path("/").Methods("GET").HandlerFunc(uiMain).Name(appmonUIMain)
return rt
}
示例2: InitAnswerRoutes
func InitAnswerRoutes(r *mux.Router) *mux.Router {
//PUT
r.Path("/{category:[a-z]+}/{questionID:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/answer}").Methods("PUT").Name(CreatePendingAnswer)
r.Path("/{category:[a-z]+}/answer/{answerID:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/vote/{vote:-1|1}}").Methods("PUT").Name(UpdateAnswerVote)
return r
}
示例3: PopulateRouter
// PopulateRouter adds all Coordinate URL paths to a router.
func (api *restAPI) PopulateRouter(r *mux.Router) {
api.PopulateNamespace(r)
r.Path("/").Name("root").Handler(&resourceHandler{
Representation: restdata.RootData{},
Context: api.Context,
Get: api.RootDocument,
})
}
示例4: setupApiApps
func setupApiApps(apirouter *mux.Router, domainmgr DomainManager, usermgr UserManager) {
prefix, _ := apirouter.Path("/").URL()
apirouter.PathPrefix("/v1").Handler(
context.ClearHandler(HandlerList{
SilentHandler(SessionHandler(options.SessionStore, int(options.SessionTTL/time.Second))),
SilentHandler(BasicAuth(usermgr)),
SilentHandler(ValidateUID(usermgr)),
http.StripPrefix(prefix.Path+"v1", NewAPIv1(domainmgr, usermgr)),
}))
}
示例5: DocHandle
/*
DocHandle registeres a path/method/api version route in the provided router, handled by the provided f, wrapping it in appstats.NewHandler,
registering the f-function and its route with jsoncontext.Document and then using jsoncontext.Handle to do something that acts like
JSONHandlerFunc.
*/
func DocHandle(router *mux.Router, f interface{}, path string, method string, minAPIVersion, maxAPIVersion int, scopes ...string) {
doc, fu := jsoncontext.Document(f, path, method, minAPIVersion, maxAPIVersion, scopes...)
jsoncontext.Remember(doc)
router.Path(path).Methods(method).Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gaeCont := appengine.NewContext(r)
c := NewJSONContext(gaeCont, jsoncontext.NewJSONContext(httpcontext.NewHTTPContext(w, r)))
jsoncontext.Handle(c, func() (resp jsoncontext.Resp, err error) {
return fu(c)
}, minAPIVersion, maxAPIVersion, scopes...)
}))
}
示例6: dashboardRoutes
func (a *AgentCommand) dashboardRoutes(r *mux.Router) {
r.Path("/" + dashboardPathPrefix).HandlerFunc(a.dashboardIndexHandler)
subui := r.PathPrefix("/" + dashboardPathPrefix).Subrouter()
subui.HandleFunc("/jobs", a.dashboardJobsHandler)
subui.HandleFunc("/jobs/{job}/executions", a.dashboardExecutionsHandler)
// Path of static files must be last!
r.PathPrefix("/dashboard").Handler(
http.StripPrefix("/dashboard", http.FileServer(
http.Dir(filepath.Join(a.config.UIDir, "static")))))
}
示例7: Routes
func Routes(r *mux.Router) {
ps := r.Path("/paintings").Subrouter()
ps.Methods("GET").Handler(listPaintings)
ps.Methods("POST").Handler(createPainting)
r.Methods("GET").Path("/paintings/categories").Handler(listCategories)
r.Methods("GET").Path("/paintings/media").Handler(listMedia)
p := r.Path("/paintings/{ID:[0-9]+}").Subrouter()
p.Methods("GET").Handler(showPainting)
p.Methods("PUT").Handler(editPainting)
r.Methods("POST").Path("/paintings/{ID:[0-9]+}/rotate").Handler(rotatePainting)
}
示例8: SetupRoutes
func (m *overchanMiddleware) SetupRoutes(mux *mux.Router) {
// setup front page handler
mux.Path("/").HandlerFunc(m.ServeIndex)
// setup thread handler
mux.Path("/thread/{id}/").HandlerFunc(m.ServeThread)
// setup board page handler
mux.Path("/board/{name}/").HandlerFunc(m.ServeBoardPage)
// setup posting endpoint
mux.Path("/post")
// create captcha
captchaPrefix := "/captcha/"
m.captcha = NewCaptchaServer(200, 400, captchaPrefix, m.store)
// setup captcha endpoint
m.captcha.SetupRoutes(mux.PathPrefix(captchaPrefix).Subrouter())
}
示例9: createRoute
func createRoute(router *mux.Router, route Route) {
r := router.
Path(route.Path).
Name(route.Name)
if route.Headers != nil {
r.Headers(route.Headers...)
}
if route.Queries != nil {
r.Queries(route.Queries...)
}
if route.Schemes != nil {
r.Schemes(route.Schemes...)
}
if route.Methods != nil {
r.Methods(route.Methods...)
}
if route.Host != "" {
r.Host(route.Host)
}
r.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := route.Handler
for _, middleware := range route.Middleware {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
})
}
示例10: apiRoutes
func (a *AgentCommand) apiRoutes(r *mux.Router) {
r.Path("/v1").HandlerFunc(a.indexHandler)
subver := r.PathPrefix("/v1").Subrouter()
subver.HandleFunc("/members", a.membersHandler)
subver.HandleFunc("/leader", a.leaderHandler)
subver.Path("/jobs").HandlerFunc(a.jobCreateOrUpdateHandler).Methods("POST", "PATCH")
subver.Path("/jobs").HandlerFunc(a.jobsHandler).Methods("GET")
sub := subver.PathPrefix("/jobs").Subrouter()
sub.HandleFunc("/{job}", a.jobGetHandler).Methods("GET")
sub.HandleFunc("/{job}", a.jobDeleteHandler).Methods("DELETE")
sub.HandleFunc("/{job}", a.jobRunHandler).Methods("POST")
subex := subver.PathPrefix("/executions").Subrouter()
subex.HandleFunc("/{job}", a.executionsHandler).Methods("GET")
}
示例11: setupAuthApps
func setupAuthApps(authrouter *mux.Router, usermgr UserManager) {
for _, authkey := range options.AuthKeys {
authconfig, ok := (*options.AuthConfigs)[authkey.Name]
if !ok {
log.Printf("Unknown authenticator \"%s\", skipping", authkey.Name)
continue
}
authconfig.AuthKey = authkey
var auth Authenticator
var ex Extractor
prefix, _ := authrouter.Path("/" + authkey.Name).URL()
switch authconfig.Extractor.Type {
case "json":
ex = NewJSONExtractor(authconfig.Extractor.URL, authconfig.Extractor.Field)
default:
log.Printf("Unknown extractor \"%s\", skipping", authconfig.Extractor.Type)
continue
}
switch authconfig.Type {
case "oauth":
log.Printf("Enabling %s OAuth on %s with ClientID %s", authkey.Name, prefix.String(), authconfig.AuthKey.ClientID)
auth = NewOAuthAuthenticator(authkey.Name, &oauth.Config{
ClientId: authconfig.AuthKey.ClientID,
ClientSecret: authconfig.AuthKey.Secret,
AuthURL: authconfig.AuthURL,
TokenURL: authconfig.TokenURL,
Scope: authconfig.Scope,
RedirectURL: prefix.String() + "/callback",
}, ex, usermgr)
default:
log.Printf("Unknown authenticator \"%s\", skipping", authconfig.Type)
continue
}
authrouter.PathPrefix("/" + authkey.Name).Handler(
context.ClearHandler(HandlerList{
SilentHandler(SessionHandler(options.SessionStore, int(options.SessionTTL/time.Second))),
http.StripPrefix(prefix.Path, auth),
}))
}
authrouter.Handle("/", authListHandler(options.AuthConfigs))
authrouter.Path("/logout").Handler(
context.ClearHandler(HandlerList{
SilentHandler(SessionHandler(options.SessionStore, int(options.SessionTTL/time.Second))),
http.HandlerFunc(LogoutHandler),
}))
}
示例12: PopulateNamespace
// PopulateNamespace adds namespace-specific routes to a router.
// r should be rooted at the root of the Coordinate URL tree, e.g. "/".
func (api *restAPI) PopulateNamespace(r *mux.Router) {
r.Path("/namespace").Name("namespaces").Handler(&resourceHandler{
Representation: restdata.NamespaceShort{},
Context: api.Context,
Get: api.NamespaceList,
Post: api.NamespacePost,
})
r.Path("/namespace/{namespace}").Name("namespace").Handler(&resourceHandler{
Representation: restdata.Namespace{},
Context: api.Context,
Get: api.NamespaceGet,
Delete: api.NamespaceDelete,
})
sr := r.PathPrefix("/namespace/{namespace}").Subrouter()
api.PopulateWorkSpec(sr)
api.PopulateWorker(sr)
}
示例13: setupPaymentsRoutes
func setupPaymentsRoutes(r *mux.Router) {
client := redis.NewTCPClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
store := &RedisStorage{
Client: client,
}
ph := NewPaymentsHandler(store)
r.
Path("/api/payments/{id}").
Methods("GET").
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
p, err := ph.Get(id)
if err != nil {
http.Error(w, "Not found", http.StatusNotFound)
return
}
renderAsJson(w, p)
})
r.
Path("/api/payments").
Methods("POST").
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var p Payments
err := decoder.Decode(&p)
if err != nil {
http.Error(w, "Bad data", http.StatusBadRequest)
return
}
p, err = ph.Create(p)
if err != nil {
http.Error(w, "Err", http.StatusInternalServerError)
return
}
renderAsJson(w, p)
})
}
示例14: SetupRoutes
// SetupRoutes populates the routes for the REST interface
func SetupRoutes(r *mux.Router) {
// API v1
r.Path("/api/v1/mailbox/{name}").Handler(httpd.Handler(MailboxListV1)).Name("MailboxListV1").Methods("GET")
r.Path("/api/v1/mailbox/{name}").Handler(httpd.Handler(MailboxPurgeV1)).Name("MailboxPurgeV1").Methods("DELETE")
r.Path("/api/v1/mailbox/{name}/{id}").Handler(httpd.Handler(MailboxShowV1)).Name("MailboxShowV1").Methods("GET")
r.Path("/api/v1/mailbox/{name}/{id}").Handler(httpd.Handler(MailboxDeleteV1)).Name("MailboxDeleteV1").Methods("DELETE")
r.Path("/api/v1/mailbox/{name}/{id}/source").Handler(httpd.Handler(MailboxSourceV1)).Name("MailboxSourceV1").Methods("GET")
}
示例15: InitQuestionRoutes
func InitQuestionRoutes(r *mux.Router) *mux.Router {
//GET
r.Path("/post/{questionId:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}").Methods("GET").Name(ReadPost)
r.Path("/questions/{filter:posted-by|answered-by|category}/{val:[A-Za-z0-9]+}").Methods("GET").Name(ReadQuestionsByFilter)
r.Path("/{postComponent:questions|answers}/{sortedBy:upvotes|edits|date}/{order:desc|asc}/{offset:[0-9]+}").Methods("GET").Name(ReadSortedQuestions)
//POST
r.Path("/question/{category:[a-z]+}").Methods("POST").Name(CreateQuestion)
return r
}