示例#1
0
文件: mod.go 项目: lichia/hydra
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
}
示例#2
0
文件: handler.go 项目: lichia/hydra
// 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
}
示例#3
0
文件: handler.go 项目: lichia/hydra
// 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
}
示例#4
0
文件: server.go 项目: lichia/hydra
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
}
示例#5
0
文件: server.go 项目: lichia/hydra
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")
}
示例#6
0
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
}