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


Golang mux.NewRouter函数代码示例

本文整理汇总了Golang中github.com/coreos/etcd/third_party/github.com/gorilla/mux.NewRouter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRouter函数的具体用法?Golang NewRouter怎么用?Golang NewRouter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: HTTPHandler

func (s *PeerServer) HTTPHandler() http.Handler {
	router := mux.NewRouter()

	// internal commands
	router.HandleFunc("/name", s.NameHttpHandler)
	router.HandleFunc("/version", s.VersionHttpHandler)
	router.HandleFunc("/version/{version:[0-9]+}/check", s.VersionCheckHttpHandler)
	router.HandleFunc("/upgrade", s.UpgradeHttpHandler)
	router.HandleFunc("/join", s.JoinHttpHandler)
	router.HandleFunc("/remove/{name:.+}", s.RemoveHttpHandler)
	router.HandleFunc("/vote", s.VoteHttpHandler)
	router.HandleFunc("/log", s.GetLogHttpHandler)
	router.HandleFunc("/log/append", s.AppendEntriesHttpHandler)
	router.HandleFunc("/snapshot", s.SnapshotHttpHandler)
	router.HandleFunc("/snapshotRecovery", s.SnapshotRecoveryHttpHandler)
	router.HandleFunc("/etcdURL", s.EtcdURLHttpHandler)

	router.HandleFunc("/v2/admin/config", s.getClusterConfigHttpHandler).Methods("GET")
	router.HandleFunc("/v2/admin/config", s.setClusterConfigHttpHandler).Methods("PUT")
	router.HandleFunc("/v2/admin/machines", s.getMachinesHttpHandler).Methods("GET")
	router.HandleFunc("/v2/admin/machines/{name}", s.getMachineHttpHandler).Methods("GET")
	router.HandleFunc("/v2/admin/machines/{name}", s.RemoveHttpHandler).Methods("DELETE")

	return router
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:25,代码来源:peer_server.go

示例2: HttpHandler

func HttpHandler(addr string) http.Handler {
	r := mux.NewRouter()
	r.HandleFunc("/dashboard", addSlash)
	r.PathPrefix("/dashboard/").Handler(http.StripPrefix("/dashboard/", dashboard.HttpHandler()))

	r.PathPrefix("/v2/lock").Handler(http.StripPrefix("/v2/lock", lock2.NewHandler(addr)))
	r.PathPrefix("/v2/leader").Handler(http.StripPrefix("/v2/leader", leader2.NewHandler(addr)))
	return r
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:9,代码来源:mod.go

示例3: NewHandler

// NewHandler creates an HTTP handler that can be registered on a router.
func NewHandler(addr string) http.Handler {
	h := &handler{
		Router: mux.NewRouter(),
		client: etcd.NewClient([]string{addr}),
	}
	h.StrictSlash(false)
	h.handleFunc("/{key:.*}", h.getIndexHandler).Methods("GET")
	h.handleFunc("/{key:.*}", h.acquireHandler).Methods("POST")
	h.handleFunc("/{key:.*}", h.renewLockHandler).Methods("PUT")
	h.handleFunc("/{key:.*}", h.releaseLockHandler).Methods("DELETE")
	return h
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:13,代码来源:handler.go

示例4: NewHandler

// NewHandler creates an HTTP handler that can be registered on a router.
func NewHandler(addr string) http.Handler {
	transport := &http.Transport{DisableKeepAlives: false}
	h := &handler{
		Router:    mux.NewRouter(),
		client:    &http.Client{Transport: transport},
		transport: transport,
		addr:      addr,
	}
	h.StrictSlash(false)
	h.handleFunc("/{key:.*}", h.getHandler).Methods("GET")
	h.handleFunc("/{key:.*}", h.setHandler).Methods("PUT")
	h.handleFunc("/{key:.*}", h.deleteHandler).Methods("DELETE")
	return h
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:15,代码来源:handler.go

示例5: HTTPHandler

func (s *Server) HTTPHandler() http.Handler {
	router := mux.NewRouter()

	// Install the routes.
	s.handleFunc(router, "/version", s.GetVersionHandler).Methods("GET")
	s.installV1(router)
	s.installV2(router)
	s.installMod(router)

	if s.trace {
		s.installDebug(router)
	}

	return router
}
开发者ID:kakkartushar1,项目名称:ArangoDB,代码行数:15,代码来源:server.go

示例6: installV2

func (s *Server) installV2(r *mux.Router) {
	r2 := mux.NewRouter()
	r.PathPrefix("/v2").Handler(ehttp.NewLowerQueryParamsHandler(r2))

	s.handleFuncV2(r2, "/v2/keys/{key:.*}", v2.GetHandler).Methods("GET")
	s.handleFuncV2(r2, "/v2/keys/{key:.*}", v2.PostHandler).Methods("POST")
	s.handleFuncV2(r2, "/v2/keys/{key:.*}", v2.PutHandler).Methods("PUT")
	s.handleFuncV2(r2, "/v2/keys/{key:.*}", v2.DeleteHandler).Methods("DELETE")
	s.handleFunc(r2, "/v2/leader", s.GetLeaderHandler).Methods("GET")
	s.handleFunc(r2, "/v2/machines", s.GetPeersHandler).Methods("GET")
	s.handleFunc(r2, "/v2/peers", s.GetPeersHandler).Methods("GET")
	s.handleFunc(r2, "/v2/stats/self", s.GetStatsHandler).Methods("GET")
	s.handleFunc(r2, "/v2/stats/leader", s.GetLeaderStatsHandler).Methods("GET")
	s.handleFunc(r2, "/v2/stats/store", s.GetStoreStatsHandler).Methods("GET")
	s.handleFunc(r2, "/v2/speedTest", s.SpeedTestHandler).Methods("GET")
}
开发者ID:kakkartushar1,项目名称:ArangoDB,代码行数:16,代码来源:server.go

示例7: HTTPHandler

func (s *Server) HTTPHandler() http.Handler {
	router := mux.NewRouter()

	// Install the routes.
	s.handleFunc(router, "/version", s.GetVersionHandler).Methods("GET")
	s.installV1(router)
	s.installV2(router)
	// Mod is deprecated temporariy due to its unstable state.
	// It would be added back later.
	// s.installMod(router)

	if s.trace {
		s.installDebug(router)
	}

	return router
}
开发者ID:BREWTAN,项目名称:etcd,代码行数:17,代码来源:server.go

示例8: HTTPHandler

func (s *PeerServer) HTTPHandler() http.Handler {
	router := mux.NewRouter()

	// internal commands
	router.HandleFunc("/name", s.NameHttpHandler)
	router.HandleFunc("/version", s.VersionHttpHandler)
	router.HandleFunc("/version/{version:[0-9]+}/check", s.VersionCheckHttpHandler)
	router.HandleFunc("/upgrade", s.UpgradeHttpHandler)
	router.HandleFunc("/join", s.JoinHttpHandler)
	router.HandleFunc("/remove/{name:.+}", s.RemoveHttpHandler)
	router.HandleFunc("/vote", s.VoteHttpHandler)
	router.HandleFunc("/log", s.GetLogHttpHandler)
	router.HandleFunc("/log/append", s.AppendEntriesHttpHandler)
	router.HandleFunc("/snapshot", s.SnapshotHttpHandler)
	router.HandleFunc("/snapshotRecovery", s.SnapshotRecoveryHttpHandler)
	router.HandleFunc("/etcdURL", s.EtcdURLHttpHandler)

	return router
}
开发者ID:kakkartushar1,项目名称:ArangoDB,代码行数:19,代码来源:peer_server.go


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