config.go 1003 B

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