Ver código fonte

Merge pull request #39868 from dmcgowan/remove-dead-swaprouter

Remove dead code from api server for router swapping
Brian Goff 5 anos atrás
pai
commit
fdf7f4d4ea
2 arquivos alterados com 5 adições e 41 exclusões
  1. 0 30
      api/server/router_swapper.go
  2. 5 11
      api/server/server.go

+ 0 - 30
api/server/router_swapper.go

@@ -1,30 +0,0 @@
-package server // import "github.com/docker/docker/api/server"
-
-import (
-	"net/http"
-	"sync"
-
-	"github.com/gorilla/mux"
-)
-
-// routerSwapper is an http.Handler that allows you to swap
-// mux routers.
-type routerSwapper struct {
-	mu     sync.Mutex
-	router *mux.Router
-}
-
-// Swap changes the old router with the new one.
-func (rs *routerSwapper) Swap(newRouter *mux.Router) {
-	rs.mu.Lock()
-	rs.router = newRouter
-	rs.mu.Unlock()
-}
-
-// ServeHTTP makes the routerSwapper to implement the http.Handler interface.
-func (rs *routerSwapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	rs.mu.Lock()
-	router := rs.router
-	rs.mu.Unlock()
-	router.ServeHTTP(w, r)
-}

+ 5 - 11
api/server/server.go

@@ -32,11 +32,10 @@ type Config struct {
 
 // Server contains instance details for the server
 type Server struct {
-	cfg           *Config
-	servers       []*HTTPServer
-	routers       []router.Router
-	routerSwapper *routerSwapper
-	middlewares   []middleware.Middleware
+	cfg         *Config
+	servers     []*HTTPServer
+	routers     []router.Router
+	middlewares []middleware.Middleware
 }
 
 // New returns a new instance of the server based on the specified configuration.
@@ -80,7 +79,7 @@ func (s *Server) Close() {
 func (s *Server) serveAPI() error {
 	var chErrors = make(chan error, len(s.servers))
 	for _, srv := range s.servers {
-		srv.srv.Handler = s.routerSwapper
+		srv.srv.Handler = s.createMux()
 		go func(srv *HTTPServer) {
 			var err error
 			logrus.Infof("API listen on %s", srv.l.Addr())
@@ -153,11 +152,6 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc {
 // This method also enables the Go profiler.
 func (s *Server) InitRouter(routers ...router.Router) {
 	s.routers = append(s.routers, routers...)
-
-	m := s.createMux()
-	s.routerSwapper = &routerSwapper{
-		router: m,
-	}
 }
 
 type pageNotFoundError struct{}