If TTL is nil it might bail

This commit is contained in:
Asim 2016-01-27 00:32:16 +00:00
parent 7183601d3b
commit 61094fefe8

View File

@ -179,19 +179,29 @@ func (c *consulRegistry) Register(s *Service, opts ...RegisterOption) error {
tags = append(tags, encodeEndpoints(s.Endpoints)...)
tags = append(tags, encodeVersion(s.Version))
var check *consul.AgentServiceCheck
if options.TTL > time.Duration(0) {
check = &consul.AgentServiceCheck{
TTL: fmt.Sprintf("%v", options.TTL),
}
}
if err := c.Client.Agent().ServiceRegister(&consul.AgentServiceRegistration{
ID: node.Id,
Name: s.Name,
Tags: tags,
Port: node.Port,
Address: node.Address,
Check: &consul.AgentServiceCheck{
TTL: fmt.Sprintf("%v", options.TTL),
},
Check: check,
}); err != nil {
return err
}
if options.TTL == time.Duration(0) {
return nil
}
return c.Client.Agent().PassTTL("service:"+node.Id, "")
}