config.go 562 B

123456789101112131415161718192021222324252627
  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. }
  10. // HasAccount returns if account provided.
  11. func (c EtcdConf) HasAccount() bool {
  12. return len(c.User) > 0 && len(c.Pass) > 0
  13. }
  14. // Validate validates c.
  15. func (c EtcdConf) Validate() error {
  16. if len(c.Hosts) == 0 {
  17. return errors.New("empty etcd hosts")
  18. } else if len(c.Key) == 0 {
  19. return errors.New("empty etcd key")
  20. } else {
  21. return nil
  22. }
  23. }