Refactor internal/server/user package structure

Co-authored-by: Roberto Abdelkader Martínez Pérez <robertomartinezp@gmail.com>
This commit is contained in:
pancho horrillo
2019-10-08 17:22:09 +02:00
parent 6df4369358
commit e0dd6f5dd5
6 changed files with 25 additions and 12 deletions
+30
View File
@@ -0,0 +1,30 @@
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)
}