mirror of https://github.com/status-im/consul.git
Creates a registration mechanism for RPC endpoints.
This commit is contained in:
parent
68f100c8df
commit
93ff33b1be
|
@ -112,9 +112,6 @@ type Server struct {
|
||||||
// Connection pool to other consul servers
|
// Connection pool to other consul servers
|
||||||
connPool *pool.ConnPool
|
connPool *pool.ConnPool
|
||||||
|
|
||||||
// Endpoints holds our RPC endpoints
|
|
||||||
endpoints endpoints
|
|
||||||
|
|
||||||
// eventChLAN is used to receive events from the
|
// eventChLAN is used to receive events from the
|
||||||
// serf cluster in the datacenter
|
// serf cluster in the datacenter
|
||||||
eventChLAN chan serf.Event
|
eventChLAN chan serf.Event
|
||||||
|
@ -218,21 +215,6 @@ type Server struct {
|
||||||
shutdownLock sync.Mutex
|
shutdownLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Holds the RPC endpoints
|
|
||||||
type endpoints struct {
|
|
||||||
ACL *ACL
|
|
||||||
Catalog *Catalog
|
|
||||||
Coordinate *Coordinate
|
|
||||||
Health *Health
|
|
||||||
Internal *Internal
|
|
||||||
KVS *KVS
|
|
||||||
Operator *Operator
|
|
||||||
PreparedQuery *PreparedQuery
|
|
||||||
Session *Session
|
|
||||||
Status *Status
|
|
||||||
Txn *Txn
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServer(config *Config) (*Server, error) {
|
func NewServer(config *Config) (*Server, error) {
|
||||||
return NewServerLogger(config, nil, new(token.Store))
|
return NewServerLogger(config, nil, new(token.Store))
|
||||||
}
|
}
|
||||||
|
@ -624,33 +606,23 @@ func (s *Server) setupRaft() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// endpointFactory is a function that returns an RPC endpoint bound to the given
|
||||||
|
// server.
|
||||||
|
type factory func(s *Server) interface{}
|
||||||
|
|
||||||
|
// endpoints is a list of registered RPC endpoint factories.
|
||||||
|
var endpoints []factory
|
||||||
|
|
||||||
|
// registerEndpoint registers a new RPC endpoint factory.
|
||||||
|
func registerEndpoint(fn factory) {
|
||||||
|
endpoints = append(endpoints, fn)
|
||||||
|
}
|
||||||
|
|
||||||
// setupRPC is used to setup the RPC listener
|
// setupRPC is used to setup the RPC listener
|
||||||
func (s *Server) setupRPC(tlsWrap tlsutil.DCWrapper) error {
|
func (s *Server) setupRPC(tlsWrap tlsutil.DCWrapper) error {
|
||||||
// Create endpoints
|
for _, fn := range endpoints {
|
||||||
s.endpoints.ACL = &ACL{s}
|
s.rpcServer.Register(fn(s))
|
||||||
s.endpoints.Catalog = &Catalog{s}
|
}
|
||||||
s.endpoints.Coordinate = NewCoordinate(s)
|
|
||||||
s.endpoints.Health = &Health{s}
|
|
||||||
s.endpoints.Internal = &Internal{s}
|
|
||||||
s.endpoints.KVS = &KVS{s}
|
|
||||||
s.endpoints.Operator = &Operator{s}
|
|
||||||
s.endpoints.PreparedQuery = &PreparedQuery{s}
|
|
||||||
s.endpoints.Session = &Session{s}
|
|
||||||
s.endpoints.Status = &Status{s}
|
|
||||||
s.endpoints.Txn = &Txn{s}
|
|
||||||
|
|
||||||
// Register the handlers
|
|
||||||
s.rpcServer.Register(s.endpoints.ACL)
|
|
||||||
s.rpcServer.Register(s.endpoints.Catalog)
|
|
||||||
s.rpcServer.Register(s.endpoints.Coordinate)
|
|
||||||
s.rpcServer.Register(s.endpoints.Health)
|
|
||||||
s.rpcServer.Register(s.endpoints.Internal)
|
|
||||||
s.rpcServer.Register(s.endpoints.KVS)
|
|
||||||
s.rpcServer.Register(s.endpoints.Operator)
|
|
||||||
s.rpcServer.Register(s.endpoints.PreparedQuery)
|
|
||||||
s.rpcServer.Register(s.endpoints.Session)
|
|
||||||
s.rpcServer.Register(s.endpoints.Status)
|
|
||||||
s.rpcServer.Register(s.endpoints.Txn)
|
|
||||||
|
|
||||||
ln, err := net.ListenTCP("tcp", s.config.RPCAddr)
|
ln, err := net.ListenTCP("tcp", s.config.RPCAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package consul
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &ACL{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &Catalog{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return NewCoordinate(s) })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &Health{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &Internal{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &KVS{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &Operator{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &PreparedQuery{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &Session{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &Status{s} })
|
||||||
|
registerEndpoint(func(s *Server) interface{} { return &Txn{s} })
|
||||||
|
}
|
Loading…
Reference in New Issue