package consul import ( "errors" "fmt" ) const ( allEths = "0.0.0.0" envPodIP = "POD_IP" defaultCheckPath = "/healthcheck" ) // Conf is the config item with the given key on etcd. type Conf struct { Host string // consul endpoint eg:127.0.0.1:8500 Key string `json:",optional"` Token string `json:",optional"` Tag []string `json:",optional"` Meta map[string]string `json:",optional"` // ttl check TTL int `json:",default=20"` // Second // http check CheckPath string `json:",default=/healthcheck"` Interval int `json:",default=10"` // Second Timeout int `json:",default=1"` // Second } // Validate validates c. func (c *Conf) Validate() error { if len(c.Host) == 0 { return errors.New("empty consul hosts") } if len(c.Key) == 0 { return errors.New("empty consul key") } if c.TTL == 0 { c.TTL = 20 } return nil } type BuildTargetConf struct { Service string Tags []string Healthy bool } func (t *BuildTargetConf) String() string { return fmt.Sprintf("service='%s' healthy='%t' tags='%v'", t.Service, t.Healthy, t.Tags) }