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:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user