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, encodeEndpoints(s.Endpoints)...)
tags = append(tags, encodeVersion(s.Version)) 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{ if err := c.Client.Agent().ServiceRegister(&consul.AgentServiceRegistration{
ID: node.Id, ID: node.Id,
Name: s.Name, Name: s.Name,
Tags: tags, Tags: tags,
Port: node.Port, Port: node.Port,
Address: node.Address, Address: node.Address,
Check: &consul.AgentServiceCheck{ Check: check,
TTL: fmt.Sprintf("%v", options.TTL),
},
}); err != nil { }); err != nil {
return err return err
} }
if options.TTL == time.Duration(0) {
return nil
}
return c.Client.Agent().PassTTL("service:"+node.Id, "") return c.Client.Agent().PassTTL("service:"+node.Id, "")
} }