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