Debian Codegraph @

handlers/state.go

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