1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
package handlers
import (
"net/url"
"sync"
)
// State is the discovery server configuration
// state shared between handlers.
type State struct {
mu sync.RWMutex
etcdHost string
etcdCURL *url.URL
currentLeader string
discHost string
}
func (st *State) endpoint() (ep string) {
st.mu.RLock()
ep = st.etcdHost
st.mu.RUnlock()
return ep
}
func (st *State) getCurrentLeader() (leader string) {
st.mu.RLock()
leader = st.currentLeader
st.mu.RUnlock()
return leader
}
func (st *State) setCurrentLeader(leader string) {
st.mu.Lock()
st.currentLeader = leader
st.mu.Unlock()
}
|