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


Golang Router.PathPrefix方法代码示例

本文整理汇总了Golang中github.com/gorilla/mux.Router.PathPrefix方法的典型用法代码示例。如果您正苦于以下问题:Golang Router.PathPrefix方法的具体用法?Golang Router.PathPrefix怎么用?Golang Router.PathPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/gorilla/mux.Router的用法示例。


在下文中一共展示了Router.PathPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SetupRoutes

func SetupRoutes(r *mux.Router) {
	adminRouter := r.PathPrefix("/admin").Subrouter()
	adminRouter.Handle("/users", authAdminUser(admin.UserIndexController)).Methods("GET")
	adminRouter.Handle("/users/{id:[0-9]+}/edit", authAdminUser(admin.UserEditController)).Methods("GET")
	adminRouter.Handle("/users/{id:[0-9]+}/edit", authAdminUser(admin.UserUpdateController)).Methods("POST")
	adminRouter.Handle("/users/{id:[0-9]+}/delete", authAdminUser(admin.UserDeleteController)).Methods("POST")

	apiRouter := r.PathPrefix("/api").Subrouter()
	apiRouter.Handle("/jobs", authUser(job.IndexController)).Methods("GET")
	apiRouter.Handle("/jobs/{id:[0-9]+}", authUser(job.ShowController)).Methods("GET")
	apiRouter.Handle("/jobs", authUser(job.CreateController)).Methods("POST")
	apiRouter.Handle("/jobs/{id:[0-9]+}", authUser(job.UpdateController)).Methods("PUT")
	apiRouter.Handle("/jobs/{id:[0-9]+}", authUser(job.DeleteController)).Methods("DELETE")
	apiRouter.Handle("/plans/{id:[0-9]+}", authUser(plan.ShowController)).Methods("GET")
	apiRouter.Handle("/plans", authUser(plan.CreateController)).Methods("POST")
	apiRouter.Handle("/plans/{id:[0-9]+}", authUser(plan.UpdateController)).Methods("PUT")
	apiRouter.Handle("/plans/{id:[0-9]+}", authUser(plan.DeleteController)).Methods("DELETE")

	r.Handle("/app", authUser(app.AppController)).Methods("GET")

	r.Handle("/user", redirectUser(user.CreateController)).Methods("POST")
	r.Handle("/user/edit", authUser(user.EditController)).Methods("GET")
	r.Handle("/user/edit", authUser(user.UpdateController)).Methods("POST")
	r.Handle("/user/sign_in", redirectUser(user.LoginController)).Methods("POST")
	// Ideally we want this to be a DELETE method but it is a bitch to send a DELETE
	// request client side.  POST will do for now.
	r.Handle("/user/sign_out", authUser(user.LogoutController)).Methods("POST")

	r.HandleFunc("/mobile", mobile.MobileController).Methods("GET")
	r.Handle("/", redirectUser(marketing.HomeController)).Methods("GET")
}
开发者ID:ShaneBurkhart,项目名称:GoWebScaffold,代码行数:31,代码来源:routes.go

示例2: restAPI

func restAPI(r *mux.Router) {
	sr := r.PathPrefix("/_api/").MatcherFunc(adminRequired).Subrouter()
	sr.HandleFunc("/buckets",
		restGetBuckets).Methods("GET")
	sr.HandleFunc("/buckets",
		restPostBucket).Methods("POST")
	sr.HandleFunc("/buckets/{bucketname}",
		restGetBucket).Methods("GET")
	sr.HandleFunc("/buckets/{bucketname}",
		restDeleteBucket).Methods("DELETE")
	sr.HandleFunc("/buckets/{bucketname}/compact",
		restPostBucketCompact).Methods("POST")
	sr.HandleFunc("/buckets/{bucketname}/flushDirty",
		restPostBucketFlushDirty).Methods("POST")
	sr.HandleFunc("/buckets/{bucketname}/stats",
		restGetBucketStats).Methods("GET")
	sr.HandleFunc("/bucketsRescan",
		restPostBucketsRescan).Methods("POST")
	sr.HandleFunc("/profile/cpu",
		restProfileCPU).Methods("POST")
	sr.HandleFunc("/profile/memory",
		restProfileMemory).Methods("POST")
	sr.HandleFunc("/runtime",
		restGetRuntime).Methods("GET")
	sr.HandleFunc("/runtime/memStats",
		restGetRuntimeMemStats).Methods("GET")
	sr.HandleFunc("/runtime/gc",
		restPostRuntimeGC).Methods("POST")
	sr.HandleFunc("/settings",
		restGetSettings).Methods("GET")

	r.PathPrefix("/_api/").HandlerFunc(authError)
}
开发者ID:scottcagno,项目名称:cbgb,代码行数:33,代码来源:rest.go

示例3: InitAdmin

func InitAdmin(r *mux.Router) {
	l4g.Debug("Initializing admin api routes")

	sr := r.PathPrefix("/admin").Subrouter()
	sr.Handle("/logs", ApiUserRequired(getLogs)).Methods("GET")
	sr.Handle("/client_props", ApiAppHandler(getClientProperties)).Methods("GET")
}
开发者ID:saitodisse,项目名称:platform,代码行数:7,代码来源:admin.go

示例4: addRoutesToRouter

func (this V1HttpApi) addRoutesToRouter(router *mux.Router) {
	v1 := router.PathPrefix("/v1/").Subrouter()
	v1.HandleFunc("/log/{__level}/{__category}/{__slug}/", this.PostLogHandler).Methods("POST")
	v1.HandleFunc("/log/bulk/", this.PostBulkLogHandler).Methods("POST")
	v1.HandleFunc("/ping", this.PingHandler)
	v1.HandleFunc("/ping/", this.PingHandler)
}
开发者ID:KSCTECHNOLOGIES,项目名称:uberlog,代码行数:7,代码来源:http_api.go

示例5: InitLicense

func InitLicense(r *mux.Router) {
	l4g.Debug("Initializing license api routes")

	sr := r.PathPrefix("/license").Subrouter()
	sr.Handle("/add", ApiAdminSystemRequired(addLicense)).Methods("POST")
	sr.Handle("/remove", ApiAdminSystemRequired(removeLicense)).Methods("POST")
}
开发者ID:mokamo,项目名称:platform,代码行数:7,代码来源:license.go

示例6: AddRoutesWithMiddleware

//AddRoutesWithMiddleware will add annotate routes to the given router, using the specified prefix. It accepts two middleware functions that will be applied to each route,
//depending on whether they are a "read" operation, or a "write" operation
func AddRoutesWithMiddleware(router *mux.Router, prefix string, b []backend.Backend, enableUI, useLocalAssets bool, readMiddleware, modifyMiddleware func(http.HandlerFunc) http.Handler) error {
	if readMiddleware == nil {
		readMiddleware = noopMiddleware
	}
	if modifyMiddleware == nil {
		modifyMiddleware = noopMiddleware
	}
	backends = b
	router.Handle(prefix+"/annotation", modifyMiddleware(InsertAnnotation)).Methods("POST", "PUT")
	router.Handle(prefix+"/annotation/query", readMiddleware(GetAnnotations)).Methods("GET")
	router.Handle(prefix+"/annotation/{id}", readMiddleware(GetAnnotation)).Methods("GET")
	router.Handle(prefix+"/annotation/{id}", modifyMiddleware(InsertAnnotation)).Methods("PUT")
	router.Handle(prefix+"/annotation/{id}", modifyMiddleware(DeleteAnnotation)).Methods("DELETE")
	router.Handle(prefix+"/annotation/values/{field}", readMiddleware(GetFieldValues)).Methods("GET")
	if !enableUI {
		return nil
	}
	webFS := FS(useLocalAssets)
	index, err := webFS.Open("/static/index.html")
	if err != nil {
		return fmt.Errorf("Error opening static file: %v", err)
	}
	indexHTML, err = ioutil.ReadAll(index)
	if err != nil {
		return err
	}
	router.PathPrefix("/static/").Handler(http.FileServer(webFS))
	router.PathPrefix("/").Handler(readMiddleware(Index)).Methods("GET")
	return nil
}
开发者ID:bosun-monitor,项目名称:annotate,代码行数:32,代码来源:web.go

示例7: setupApiRoutes

func setupApiRoutes(r *mux.Router) {
	// api
	a := r.PathPrefix(data.ApiUrlSuffix).Subrouter()

	// user
	a.HandleFunc("/{user}", userHandler)
	u := a.PathPrefix("/{user}").Subrouter()
	u.StrictSlash(true)

	u.HandleFunc("/", userHandler).Methods("GET")
	u.HandleFunc("/user/add", userAddHandler).Methods("POST")
	u.HandleFunc("/user/info", userInfoHandler).Methods("GET", "POST")
	u.HandleFunc("/user/pass", userPassHandler).Methods("POST")
	u.HandleFunc("/user/auth", userAuthHandler).Methods("POST")
	u.HandleFunc("/user/awscred", userAwsCredHandler).Methods("GET")

	// user/dataset
	u.HandleFunc("/{dataset}", dsHomeHandler)
	d := u.PathPrefix("/{dataset}").Subrouter()
	d.StrictSlash(true)

	dget := d.Methods("GET").Subrouter()
	// dpost := d.Methods("POST").Subrouter()

	dget.HandleFunc("/", dsHomeHandler)
	dget.HandleFunc("/Datafile", dsDatafileHandler)
	dget.HandleFunc("/refs", dsRefsHandler)
	d.HandleFunc("/refs/{ref}", dsRefHandler).Methods("GET", "POST")
	// dget.HandleFunc("/tree/{ref}/", dsTreeHandler)
	dget.HandleFunc("/blob/{ref}/", dsBlobHandler)
	dget.HandleFunc("/archive/", dsArchivesHandler)
	dget.HandleFunc("/archives/", dsArchivesHandler)
	dget.HandleFunc("/archive/{ref}.tar.gz", dsDownloadArchiveHandler)
	// dget.HandleFunc("/archive/{ref}.zip", dsArchiveHandler)
}
开发者ID:jbenet,项目名称:datadex,代码行数:35,代码来源:datadex_router.go

示例8: setupWebsiteRoutes

func setupWebsiteRoutes(r *mux.Router) {
	// serve static files
	r.HandleFunc("/static/config.js", webConfigHandler)
	r.PathPrefix("/static").Handler(http.FileServer(http.Dir("web/build/")))

	r.HandleFunc("/version", versionHandler).Methods("GET")

	// docs
	for _, p := range webDocPages {
		r.HandleFunc(p.route, webDocHandler)
	}

	// lists
	r.HandleFunc("/list/{kind}/by-{order}", webListHandler)

	// user
	r.HandleFunc("/{user}", webUserHandler)
	u := r.PathPrefix("/{user}").Subrouter()
	u.StrictSlash(true)

	u.HandleFunc("/", webUserHandler).Methods("GET")
	// u.HandleFunc("/user/add", webUserAddHandler).Methods("POST")
	// u.HandleFunc("/user/info", webUserInfoHandler).Methods("GET", "POST")
	// u.HandleFunc("/user/pass", webUserPassHandler).Methods("POST")

	// user/dataset
	u.HandleFunc("/{dataset}", webDsHomeHandler)
	// d := u.PathPrefix("/{dataset}@{ref}").Subrouter()
	// d.StrictSlash(true)

	// d.HandleFunc("/", webDsHomeHandler)
	// d.HandleFunc("/blob/", webDsBlobHandler)
}
开发者ID:jbenet,项目名称:datadex,代码行数:33,代码来源:datadex_router.go

示例9: AttachRESTHandler

// AttachRESTHandler attaches a router at the given root that hooks up REST endpoint URIs to be
// handled by the given restAPIService.
func AttachRESTHandler(root *mux.Router, service restAPIService) http.Handler {
	rtr := root.PathPrefix("/rest/v1/").Subrouter().StrictSlash(true)

	// REST routes
	rest := restAPI{service}

	//restRouter := root.PathPrefix("/rest/v1/").Subrouter().StrictSlash(true)
	rtr.HandleFunc("/projects", rest.loadCtx(rest.getProjectIds)).Name("project_list").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}", rest.loadCtx(rest.getProject)).Name("project_info").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}/versions", rest.loadCtx(rest.getRecentVersions)).Name("recent_versions").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}/revisions/{revision}", rest.loadCtx(rest.getVersionInfoViaRevision)).Name("version_info_via_revision").Methods("GET")
	rtr.HandleFunc("/projects/{project_id}/last_green", rest.loadCtx(rest.lastGreen)).Name("last_green_version").Methods("GET")
	rtr.HandleFunc("/patches/{patch_id}", rest.loadCtx(rest.getPatch)).Name("patch_info").Methods("GET")
	rtr.HandleFunc("/versions/{version_id}", rest.loadCtx(rest.getVersionInfo)).Name("version_info").Methods("GET")
	rtr.HandleFunc("/versions/{version_id}", requireUser(rest.loadCtx(rest.modifyVersionInfo), nil)).Name("").Methods("PATCH")
	rtr.HandleFunc("/versions/{version_id}/status", rest.loadCtx(rest.getVersionStatus)).Name("version_status").Methods("GET")
	rtr.HandleFunc("/versions/{version_id}/config", rest.loadCtx(rest.getVersionConfig)).Name("version_config").Methods("GET")
	rtr.HandleFunc("/builds/{build_id}", rest.loadCtx(rest.getBuildInfo)).Name("build_info").Methods("GET")
	rtr.HandleFunc("/builds/{build_id}/status", rest.loadCtx(rest.getBuildStatus)).Name("build_status").Methods("GET")
	rtr.HandleFunc("/tasks/{task_id}", rest.loadCtx(rest.getTaskInfo)).Name("task_info").Methods("GET")
	rtr.HandleFunc("/tasks/{task_id}/status", rest.loadCtx(rest.getTaskStatus)).Name("task_status").Methods("GET")
	rtr.HandleFunc("/tasks/{task_name}/history", rest.loadCtx(rest.getTaskHistory)).Name("task_history").Methods("GET")
	rtr.HandleFunc("/scheduler/host_utilization", rest.loadCtx(rest.getHostUtilizationStats)).Name("host_utilization").Methods("GET")
	rtr.HandleFunc("/scheduler/distro/{distro_id}/stats", rest.loadCtx(rest.getAverageSchedulerStats)).Name("avg_stats").Methods("GET")
	rtr.HandleFunc("/scheduler/makespans", rest.loadCtx(rest.getOptimalAndActualMakespans)).Name("makespan").Methods("GET")

	return root

}
开发者ID:tychoish,项目名称:evergreen,代码行数:31,代码来源:rest_routes.go

示例10: registerWebuiHandler

// registerWebuiHandler registers handlers for serving web UI
func registerWebuiHandler(router *mux.Router) {
	// Setup the router to serve the web UI
	goPath := os.Getenv("GOPATH")
	if goPath != "" {
		webPath := goPath + "/src/github.com/contiv/contivmodel/www/"

		// Make sure we have the web UI files
		_, err := os.Stat(webPath)
		if err != nil {
			webPath = goPath + "/src/github.com/contiv/netplugin/" +
				"Godeps/_workspace/src/github.com/contiv/contivmodel/www/"
			_, err := os.Stat(webPath)
			if err != nil {
				log.Errorf("Can not find the web UI directory")
			}
		}

		log.Infof("Using webPath: %s", webPath)

		// serve static files
		router.PathPrefix("/web/").Handler(http.StripPrefix("/web/", http.FileServer(http.Dir(webPath))))

		// Special case to serve main index.html
		router.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
			http.ServeFile(rw, req, webPath+"index.html")
		})
	}

	// proxy Handler
	router.PathPrefix("/proxy/").HandlerFunc(proxyHandler)
}
开发者ID:nikolayvoronchikhin,项目名称:netplugin,代码行数:32,代码来源:main.go

示例11: RegisterRoutes

// RegisterRoutes operates over `Routes` and registers all of them
func RegisterRoutes(router *mux.Router) *mux.Router {
	for _, route := range routes {
		router.Methods(route.Method).Path(route.Pattern).Name(route.Name).Handler(route.HandlerFunc)
	}
	router.PathPrefix("/").Handler(http.FileServer(assetFS()))
	return router
}
开发者ID:erasche,项目名称:gologme,代码行数:8,代码来源:routes.go

示例12: handlePlayground

func handlePlayground(r *mux.Router) {
	r = r.PathPrefix("/api/playground").Subrouter()

	r.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		results.View("playground/form", nil, w)
	})
}
开发者ID:vitormoura,项目名称:Laboratorio,代码行数:7,代码来源:playground.go

示例13: AddRoutes

//AddRoutes registers the http routes with the router
func (service *Service) AddRoutes(router *mux.Router) {
	router.Methods("GET").Path("/").HandlerFunc(service.HomePage)
	//Registration form
	router.Methods("GET").Path("/register").HandlerFunc(service.ShowRegistrationForm)
	router.Methods("POST").Path("/register").HandlerFunc(service.ProcessRegistrationForm)
	//Login form
	router.Methods("GET").Path("/login").HandlerFunc(service.ShowLoginForm)
	router.Methods("POST").Path("/login").HandlerFunc(service.ProcessLoginForm)
	//Logout link
	router.Methods("GET").Path("/logout").HandlerFunc(service.Logout)
	//Error page
	router.Methods("GET").Path("/error").HandlerFunc(service.ErrorPage)
	router.Methods("GET").Path("/error{errornumber}").HandlerFunc(service.ErrorPage)

	//host the assets used in the htmlpages
	router.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(
		&assetfs.AssetFS{Asset: assets.Asset, AssetDir: assets.AssetDir, AssetInfo: assets.AssetInfo})))
	router.PathPrefix("/thirdpartyassets/").Handler(http.StripPrefix("/thirdpartyassets/", http.FileServer(
		&assetfs.AssetFS{Asset: thirdpartyassets.Asset, AssetDir: thirdpartyassets.AssetDir, AssetInfo: thirdpartyassets.AssetInfo})))
	router.PathPrefix("/components/").Handler(http.StripPrefix("/components/", http.FileServer(
		&assetfs.AssetFS{Asset: components.Asset, AssetDir: components.AssetDir, AssetInfo: components.AssetInfo})))

	//host the apidocumentation
	router.Methods("GET").Path("/apidocumentation").HandlerFunc(service.APIDocs)
	router.PathPrefix("/apidocumentation/raml/").Handler(http.StripPrefix("/apidocumentation/raml", http.FileServer(
		&assetfs.AssetFS{Asset: specifications.Asset, AssetDir: specifications.AssetDir, AssetInfo: specifications.AssetInfo})))
	router.PathPrefix("/apidocumentation/").Handler(http.StripPrefix("/apidocumentation/", http.FileServer(
		&assetfs.AssetFS{Asset: apiconsole.Asset, AssetDir: apiconsole.AssetDir, AssetInfo: apiconsole.AssetInfo})))

}
开发者ID:mohabusama,项目名称:identityserver,代码行数:31,代码来源:service.go

示例14: InitUser

//InitUser Initialize user routes
func InitUser(r *mux.Router) {
	l4g.Debug("Initializing user api routes")
	sr := r.PathPrefix("/users").Subrouter()
	sr.Handle("/login", negroni.New(
		negroni.HandlerFunc(RequireContext),
		negroni.HandlerFunc(login),
	)).Methods("POST")
	sr.Handle("/create", negroni.New(
		negroni.HandlerFunc(RequireContext),
		negroni.HandlerFunc(createUser),
	)).Methods("POST")
	sr.Handle("/", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(allUsers),
	)).Methods("GET")
	sr.Handle("/{uuid}", negroni.New(
		negroni.HandlerFunc(RequireAuthAndUser),
		negroni.HandlerFunc(getUser),
	)).Methods("GET")
	sr.Handle("/{uuid}", negroni.New(
		negroni.HandlerFunc(RequireAuth),
		negroni.HandlerFunc(deleteUser),
	)).Methods("DELETE")
	sr.Handle("/{uuid}", negroni.New(
		negroni.HandlerFunc(RequireAuthAndUser),
		negroni.HandlerFunc(updateUser),
	)).Methods("POST")
}
开发者ID:sichacvah,项目名称:portable_chat,代码行数:29,代码来源:user.go

示例15: InitLicense

func InitLicense(r *mux.Router) {
	l4g.Debug(utils.T("api.license.init.debug"))

	sr := r.PathPrefix("/license").Subrouter()
	sr.Handle("/add", ApiAdminSystemRequired(addLicense)).Methods("POST")
	sr.Handle("/remove", ApiAdminSystemRequired(removeLicense)).Methods("POST")
}
开发者ID:jessezwd,项目名称:platform,代码行数:7,代码来源:license.go


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