Added zrpc server custom serverID for custom registration Key when the service is registered on ETCD. (#3008)
This commit is contained in:
@@ -13,6 +13,7 @@ var (
|
||||
type EtcdConf struct {
|
||||
Hosts []string
|
||||
Key string
|
||||
ServerID int64 `json:",optional"`
|
||||
User string `json:",optional"`
|
||||
Pass string `json:",optional"`
|
||||
CertFile string `json:",optional"`
|
||||
@@ -26,6 +27,11 @@ func (c EtcdConf) HasAccount() bool {
|
||||
return len(c.User) > 0 && len(c.Pass) > 0
|
||||
}
|
||||
|
||||
// HasServerID returns if ServerID provided.
|
||||
func (c EtcdConf) HasServerID() bool {
|
||||
return c.ServerID > 0
|
||||
}
|
||||
|
||||
// HasTLS returns if TLS CertFile/CertKeyFile/CACertFile are provided.
|
||||
func (c EtcdConf) HasTLS() bool {
|
||||
return len(c.CertFile) > 0 && len(c.CertKeyFile) > 0 && len(c.CACertFile) > 0
|
||||
|
||||
@@ -80,3 +80,36 @@ func TestEtcdConf_HasAccount(t *testing.T) {
|
||||
assert.Equal(t, test.hasAccount, test.EtcdConf.HasAccount())
|
||||
}
|
||||
}
|
||||
|
||||
func TestEtcdConf_HasServerID(t *testing.T) {
|
||||
tests := []struct {
|
||||
EtcdConf
|
||||
hasServerID bool
|
||||
}{
|
||||
{
|
||||
EtcdConf: EtcdConf{
|
||||
Hosts: []string{"any"},
|
||||
ServerID: -1,
|
||||
},
|
||||
hasServerID: false,
|
||||
},
|
||||
{
|
||||
EtcdConf: EtcdConf{
|
||||
Hosts: []string{"any"},
|
||||
ServerID: 0,
|
||||
},
|
||||
hasServerID: false,
|
||||
},
|
||||
{
|
||||
EtcdConf: EtcdConf{
|
||||
Hosts: []string{"any"},
|
||||
ServerID: 10000,
|
||||
},
|
||||
hasServerID: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
assert.Equal(t, test.hasServerID, test.EtcdConf.HasServerID())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user