當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。