2020-07-26 17:09:05 +08:00
|
|
|
package discov
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
2021-02-18 22:56:35 +08:00
|
|
|
// EtcdConf is the config item with the given key on etcd.
|
2020-07-26 17:09:05 +08:00
|
|
|
type EtcdConf struct {
|
|
|
|
Hosts []string
|
|
|
|
Key string
|
2021-10-31 09:05:38 +08:00
|
|
|
User string `json:",optional"`
|
|
|
|
Pass string `json:",optional"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasAccount returns if account provided.
|
|
|
|
func (c EtcdConf) HasAccount() bool {
|
|
|
|
return len(c.User) > 0 && len(c.Pass) > 0
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
|
|
|
|
2021-02-18 22:56:35 +08:00
|
|
|
// Validate validates c.
|
2020-07-26 17:09:05 +08:00
|
|
|
func (c EtcdConf) Validate() error {
|
|
|
|
if len(c.Hosts) == 0 {
|
|
|
|
return errors.New("empty etcd hosts")
|
|
|
|
} else if len(c.Key) == 0 {
|
|
|
|
return errors.New("empty etcd key")
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|