add RegisterCheck server option for internal health checks

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2019-05-13 01:39:42 +03:00
parent 4f5ff076d4
commit a13cdfcc34
3 changed files with 43 additions and 13 deletions

View File

@@ -25,6 +25,8 @@ type Options struct {
HdlrWrappers []HandlerWrapper
SubWrappers []SubscriberWrapper
// RegisterCheck runs a check function before registering the service
RegisterCheck func(context.Context) error
// The register expiry time
RegisterTTL time.Duration
// The interval on which to register
@@ -67,6 +69,10 @@ func newOptions(opt ...Option) Options {
opts.DebugHandler = debug.DefaultDebugHandler
}
if opts.RegisterCheck == nil {
opts.RegisterCheck = DefaultRegisterCheck
}
if len(opts.Address) == 0 {
opts.Address = DefaultAddress
}
@@ -163,6 +169,13 @@ func Metadata(md map[string]string) Option {
}
}
// RegisterCheck run func before registry service
func RegisterCheck(fn func(context.Context) error) Option {
return func(o *Options) {
o.RegisterCheck = fn
}
}
// Register the service with a TTL
func RegisterTTL(t time.Duration) Option {
return func(o *Options) {