mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
refactor(servers): emit http.Handlers from *Server
This commit is contained in:
@@ -35,7 +35,6 @@ type PeerServerConfig struct {
|
||||
|
||||
type PeerServer struct {
|
||||
Config PeerServerConfig
|
||||
handler http.Handler
|
||||
raftServer raft.Server
|
||||
server *Server
|
||||
joinIndex uint64
|
||||
@@ -77,8 +76,6 @@ func NewPeerServer(psConfig PeerServerConfig, registry *Registry, store store.St
|
||||
metrics: mb,
|
||||
}
|
||||
|
||||
s.handler = s.buildHTTPHandler()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -164,7 +161,7 @@ func (s *PeerServer) Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PeerServer) buildHTTPHandler() http.Handler {
|
||||
func (s *PeerServer) HTTPHandler() http.Handler {
|
||||
router := mux.NewRouter()
|
||||
|
||||
// internal commands
|
||||
@@ -184,10 +181,6 @@ func (s *PeerServer) buildHTTPHandler() http.Handler {
|
||||
return router
|
||||
}
|
||||
|
||||
func (s *PeerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// Retrieves the underlying Raft server.
|
||||
func (s *PeerServer) RaftServer() raft.Server {
|
||||
return s.raftServer
|
||||
|
||||
@@ -45,8 +45,6 @@ func New(name, url string, peerServer *PeerServer, registry *Registry, store sto
|
||||
metrics: mb,
|
||||
}
|
||||
|
||||
s.handler = s.buildHTTPHandler()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -169,7 +167,7 @@ func (s *Server) handleFunc(r *mux.Router, path string, f func(http.ResponseWrit
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) buildHTTPHandler() http.Handler {
|
||||
func (s *Server) HTTPHandler() http.Handler {
|
||||
router := mux.NewRouter()
|
||||
|
||||
// Install the routes.
|
||||
@@ -185,10 +183,6 @@ func (s *Server) buildHTTPHandler() http.Handler {
|
||||
return router
|
||||
}
|
||||
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.handler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// Dispatch command to the current leader
|
||||
func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Request) error {
|
||||
ps := s.peerServer
|
||||
|
||||
Reference in New Issue
Block a user