Use registry.options.Context to set Consul TCP check option

This commit is contained in:
Shulhan
2018-03-19 20:34:56 +07:00
parent f4cdfaf27f
commit 68ab671bd0
5 changed files with 36 additions and 41 deletions

View File

@@ -14,6 +14,10 @@ import (
hash "github.com/mitchellh/hashstructure"
)
const (
ConsulRegisterTCPCheckKey = "consul_register_tcp_check"
)
type consulRegistry struct {
Address string
Client *consul.Client
@@ -138,6 +142,15 @@ func (c *consulRegistry) Register(s *Service, opts ...RegisterOption) error {
o(&options)
}
if c.opts.Context != nil {
tcpCheckInterval, ok := c.opts.Context.
Value(ConsulRegisterTCPCheckKey).(time.Duration)
if ok {
options.TCPCheck = true
options.Interval = tcpCheckInterval
}
}
// create hash of service; uint64
h, err := hash.Hash(s, nil)
if err != nil {