swappableMux is now public and Append() now updates Server.Handler
Co-authored-by: Roberto Abdelkader Martínez Pérez <robertomartinezp@gmail.com>
This commit is contained in:
@@ -8,34 +8,34 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
type swappableMux struct {
|
||||
type SwappableMux struct {
|
||||
m sync.RWMutex
|
||||
root *mux.Router
|
||||
}
|
||||
|
||||
func New() *swappableMux {
|
||||
return &swappableMux{
|
||||
func New() *SwappableMux {
|
||||
return &SwappableMux{
|
||||
root: mux.NewRouter(),
|
||||
}
|
||||
}
|
||||
|
||||
func (sm *swappableMux) get() *mux.Router {
|
||||
func (sm *SwappableMux) get() *mux.Router {
|
||||
sm.m.RLock()
|
||||
defer sm.m.RUnlock()
|
||||
|
||||
return sm.root
|
||||
}
|
||||
|
||||
func (sm *swappableMux) set(mux *mux.Router) {
|
||||
func (sm *SwappableMux) set(mux *mux.Router) {
|
||||
sm.m.Lock()
|
||||
sm.root = mux
|
||||
sm.m.Unlock()
|
||||
}
|
||||
|
||||
func (sm *swappableMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func (sm *SwappableMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
sm.get().ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (sm *swappableMux) Update(rs []model.Route) {
|
||||
func (sm *SwappableMux) Update(rs []model.Route) {
|
||||
sm.set(gorillize(rs, handlerBuilder))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user