Extract Store into an interface.

This commit is contained in:
Ben Johnson
2013-10-14 11:12:30 -06:00
parent a6a32a592d
commit 1321c63f3b
14 changed files with 92 additions and 68 deletions

View File

@@ -30,7 +30,7 @@ type PeerServer struct {
followersStats *raftFollowersStats
serverStats *raftServerStats
registry *Registry
store *store.Store
store store.Store
snapConf *snapshotConf
MaxClusterSize int
RetryTimes int
@@ -49,7 +49,7 @@ type snapshotConf struct {
writesThr uint64
}
func NewPeerServer(name string, path string, url string, listenHost string, tlsConf *TLSConfig, tlsInfo *TLSInfo, registry *Registry, store *store.Store) *PeerServer {
func NewPeerServer(name string, path string, url string, listenHost string, tlsConf *TLSConfig, tlsInfo *TLSInfo, registry *Registry, store store.Store) *PeerServer {
s := &PeerServer{
name: name,
url: url,

View File

@@ -18,7 +18,7 @@ const RegistryKey = "/_etcd/machines"
// The Registry stores URL information for nodes.
type Registry struct {
sync.Mutex
store *store.Store
store store.Store
nodes map[string]*node
}
@@ -30,7 +30,7 @@ type node struct {
}
// Creates a new Registry.
func NewRegistry(s *store.Store) *Registry {
func NewRegistry(s store.Store) *Registry {
return &Registry{
store: s,
nodes: make(map[string]*node),

View File

@@ -21,7 +21,7 @@ type Server struct {
http.Server
peerServer *PeerServer
registry *Registry
store *store.Store
store store.Store
name string
url string
tlsConf *TLSConfig
@@ -30,7 +30,7 @@ type Server struct {
}
// Creates a new Server.
func New(name string, urlStr string, listenHost string, tlsConf *TLSConfig, tlsInfo *TLSInfo, peerServer *PeerServer, registry *Registry, store *store.Store) *Server {
func New(name string, urlStr string, listenHost string, tlsConf *TLSConfig, tlsInfo *TLSInfo, peerServer *PeerServer, registry *Registry, store store.Store) *Server {
s := &Server{
Server: http.Server{
Handler: mux.NewRouter(),
@@ -85,7 +85,7 @@ func (s *Server) PeerURL(name string) (string, bool) {
}
// Returns a reference to the Store.
func (s *Server) Store() *store.Store {
func (s *Server) Store() store.Store {
return s.store
}

View File

@@ -10,6 +10,6 @@ import (
type Server interface {
CommitIndex() uint64
Term() uint64
Store() *store.Store
Store() store.Store
Dispatch(raft.Command, http.ResponseWriter, *http.Request) error
}

View File

@@ -13,6 +13,6 @@ type Server interface {
CommitIndex() uint64
Term() uint64
PeerURL(string) (string, bool)
Store() *store.Store
Store() store.Store
Dispatch(raft.Command, http.ResponseWriter, *http.Request) error
}