github.com/lingyao2333/mo-zero@v1.4.1/core/discov/config.go (about) 1 package discov 2 3 import "errors" 4 5 var ( 6 // errEmptyEtcdHosts indicates that etcd hosts are empty. 7 errEmptyEtcdHosts = errors.New("empty etcd hosts") 8 // errEmptyEtcdKey indicates that etcd key is empty. 9 errEmptyEtcdKey = errors.New("empty etcd key") 10 ) 11 12 // EtcdConf is the config item with the given key on etcd. 13 type EtcdConf struct { 14 Hosts []string 15 Key string 16 User string `json:",optional"` 17 Pass string `json:",optional"` 18 CertFile string `json:",optional"` 19 CertKeyFile string `json:",optional=CertFile"` 20 CACertFile string `json:",optional=CertFile"` 21 InsecureSkipVerify bool `json:",optional"` 22 } 23 24 // HasAccount returns if account provided. 25 func (c EtcdConf) HasAccount() bool { 26 return len(c.User) > 0 && len(c.Pass) > 0 27 } 28 29 // HasTLS returns if TLS CertFile/CertKeyFile/CACertFile are provided. 30 func (c EtcdConf) HasTLS() bool { 31 return len(c.CertFile) > 0 && len(c.CertKeyFile) > 0 && len(c.CACertFile) > 0 32 } 33 34 // Validate validates c. 35 func (c EtcdConf) Validate() error { 36 if len(c.Hosts) == 0 { 37 return errEmptyEtcdHosts 38 } else if len(c.Key) == 0 { 39 return errEmptyEtcdKey 40 } else { 41 return nil 42 } 43 }