permitted the client mode to start without server addresses
This commit is contained in:
parent
db48395b13
commit
f1c146d94f
26
client.go
26
client.go
@ -1075,6 +1075,10 @@ func (c *Client) AddNewClientConn(cfg *ClientConfig) (*ClientConn, error) {
|
||||
var ok bool
|
||||
var id uint32
|
||||
|
||||
if len(cfg.ServerAddrs) <= 0 {
|
||||
return nil, fmt.Errorf("no server rpc address specified")
|
||||
}
|
||||
|
||||
cts = NewClientConn(c, cfg)
|
||||
|
||||
c.cts_mtx.Lock()
|
||||
@ -1295,17 +1299,9 @@ func (c *Client) RunTask(wg *sync.WaitGroup) {
|
||||
// so no call to wg.Done()
|
||||
}
|
||||
|
||||
func (c *Client) start_service(data interface{}) (*ClientConn, error) {
|
||||
func (c *Client) start_service(cfg *ClientConfig) (*ClientConn, error) {
|
||||
var cts *ClientConn
|
||||
var err error
|
||||
var cfg *ClientConfig
|
||||
var ok bool
|
||||
|
||||
cfg, ok = data.(*ClientConfig)
|
||||
if !ok {
|
||||
err = fmt.Errorf("invalid configuration given")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cts, err = c.AddNewClientConn(cfg)
|
||||
if err != nil {
|
||||
@ -1320,16 +1316,26 @@ func (c *Client) start_service(data interface{}) (*ClientConn, error) {
|
||||
}
|
||||
|
||||
func (c *Client) StartService(data interface{}) {
|
||||
var cfg *ClientConfig
|
||||
var ok bool
|
||||
|
||||
cfg, ok = data.(*ClientConfig)
|
||||
if !ok {
|
||||
c.log.Write("", LOG_ERROR, "Failed to start service - invalid configuration - %v", data)
|
||||
} else {
|
||||
var cts *ClientConn
|
||||
var err error
|
||||
|
||||
cts, err = c.start_service(data)
|
||||
if len(cfg.ServerAddrs) > 0 {
|
||||
cts, err = c.start_service(cfg)
|
||||
if err != nil {
|
||||
c.log.Write("", LOG_ERROR, "Failed to start service - %s", err.Error())
|
||||
} else {
|
||||
c.log.Write("", LOG_INFO, "Started service for %v [%d]", cts.cfg.ServerAddrs, cts.cfg.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) StartExtService(svc Service, data interface{}) {
|
||||
c.ext_mtx.Lock()
|
||||
|
@ -234,14 +234,11 @@ func client_main(ctl_addrs []string, rpc_addrs []string, peer_addrs []string, cf
|
||||
log_mask = log_strings_to_mask(cfg.APP.LogMask)
|
||||
}
|
||||
|
||||
if len(rpc_addrs) <= 0 {
|
||||
return fmt.Errorf("no rpc server address specified")
|
||||
}
|
||||
|
||||
// unlke the server, we allow the client to start with no rpc address.
|
||||
// no check if len(rpc_addrs) <= 0 is mdde here.
|
||||
cc.ServerAddrs = rpc_addrs
|
||||
cc.PeerAddrs = peer_addrs
|
||||
|
||||
// TODO: Change out field depending on cfg.APP.LogFile
|
||||
logger = &AppLogger{id: "client", out: os.Stderr, mask: log_mask}
|
||||
c = hodu.NewClient(
|
||||
context.Background(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user