Move swappableMux and its methods to its own module

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-10-08 09:01:40 +02:00
parent 0cab49f082
commit 22f03eb67f
4 changed files with 146 additions and 141 deletions
+25
View File
@@ -0,0 +1,25 @@
package user
import (
"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()
}