• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang mux.NewRouter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mux.Vars函数代码示例发布时间:2022-05-23
下一篇:
Golang raft.Server类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap