Files
kapow/internal/server/user/mux/mux.go
pancho horrillo e0dd6f5dd5 Refactor internal/server/user package structure
Co-authored-by: Roberto Abdelkader Martínez Pérez <robertomartinezp@gmail.com>
2019-10-08 17:22:09 +02:00

31 lines
436 B
Go

package mux
import (
"net/http"
"sync"
"github.com/gorilla/mux"
)
type swappableMux struct {
m sync.RWMutex
root *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) {
sm.m.Lock()
sm.root = mux
sm.m.Unlock()
}
func (sm *swappableMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sm.get().ServeHTTP(w, r)
}