Add New() func & Update() method to internal/server/user/mux/swappableMux

Co-authored-by: Roberto Abdelkader Martínez Pérez <robertomartinezp@gmail.com>
This commit is contained in:
pancho horrillo
2019-10-10 19:26:17 +02:00
parent 463382bfb2
commit b4dd6e9805
2 changed files with 55 additions and 0 deletions
+11
View File
@@ -4,6 +4,7 @@ import (
"net/http"
"sync"
"github.com/BBVA/kapow/internal/server/model"
"github.com/gorilla/mux"
)
@@ -12,6 +13,12 @@ type swappableMux struct {
root *mux.Router
}
func New() *swappableMux {
return &swappableMux{
root: mux.NewRouter(),
}
}
func (sm *swappableMux) get() *mux.Router {
sm.m.RLock()
defer sm.m.RUnlock()
@@ -28,3 +35,7 @@ func (sm *swappableMux) set(mux *mux.Router) {
func (sm *swappableMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sm.get().ServeHTTP(w, r)
}
func (sm *swappableMux) Update(rs []model.Route) {
sm.set(gorillize(rs, handlerBuilder))
}