2018-02-05 16:05:59 -05:00
|
|
|
package server // import "github.com/docker/docker/api/server"
|
2015-12-10 18:35:10 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2016-03-05 11:59:11 -05:00
|
|
|
// routerSwapper is an http.Handler that allows you to swap
|
2015-12-10 18:35:10 -05:00
|
|
|
// 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)
|
|
|
|
}
|