当前位置: 首页>>代码示例>>Golang>>正文


Golang Router.Path方法代码示例

本文整理汇总了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
}
开发者ID:pombredanne,项目名称:appmon,代码行数:8,代码来源:ui.go

示例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
}
开发者ID:jmheidly,项目名称:Answer-Patch,代码行数:8,代码来源:answer.go

示例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,
	})
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:9,代码来源:server.go

示例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)),
		}))
}
开发者ID:surma,项目名称:importalias,代码行数:10,代码来源:importalias.go

示例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...)
	}))
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:16,代码来源:context.go

示例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")))))
}
开发者ID:oldmantaiter,项目名称:dkron,代码行数:11,代码来源:dashboard.go

示例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)
}
开发者ID:verticalpalette,项目名称:dandubois,代码行数:14,代码来源:api.go

示例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())
}
开发者ID:majestrate,项目名称:nntpchan,代码行数:15,代码来源:overchan.go

示例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)
	})

}
开发者ID:RckMrkr,项目名称:go-api-router,代码行数:34,代码来源:router.go

示例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")
}
开发者ID:snowsnail,项目名称:dkron,代码行数:16,代码来源:api.go

示例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),
		}))
}
开发者ID:surma,项目名称:importalias,代码行数:47,代码来源:importalias.go

示例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)
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:19,代码来源:namespace.go

示例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)
		})
}
开发者ID:snichme,项目名称:expenses,代码行数:45,代码来源:main.go

示例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")
}
开发者ID:jhillyerd,项目名称:inbucket,代码行数:9,代码来源:routes.go

示例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

}
开发者ID:jmheidly,项目名称:Answer-Patch,代码行数:13,代码来源:question.go


注:本文中的github.com/gorilla/mux.Router.Path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。