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

@@ -25,9 +25,7 @@ type Options struct {
HdlrWrappers []HandlerWrapper
SubWrappers []SubscriberWrapper
RegisterTCPCheck bool
RegisterTTL time.Duration
RegisterInterval time.Duration
RegisterTTL time.Duration
// Debug Handler which can be set by a user
DebugHandler debug.DebugHandler
@@ -166,23 +164,6 @@ func RegisterTTL(t time.Duration) Option {
}
}
//
// RegisterTCPCheck will tell the service provider to check the service address
// and port every `t` interval. It will enabled only if `t` is greater than 0.
// This option is for registry using Consul, see `TCP + Interval` more
// information [1].
//
// [1] https://www.consul.io/docs/agent/checks.html
//
func RegisterTCPCheck(t time.Duration) Option {
return func(o *Options) {
if t > time.Duration(0) {
o.RegisterTCPCheck = true
o.RegisterInterval = t
}
}
}
// Wait tells the server to wait for requests to finish before exiting
func Wait(b bool) Option {
return func(o *Options) {

View File

@@ -278,10 +278,7 @@ func (s *rpcServer) Register() error {
}
// create registry options
rOpts := []registry.RegisterOption{
registry.RegisterTTL(config.RegisterTTL),
registry.RegisterTCPCheck(config.RegisterInterval),
}
rOpts := []registry.RegisterOption{registry.RegisterTTL(config.RegisterTTL)}
if err := config.Registry.Register(service, rOpts...); err != nil {
return err