add RegisterCheck server option for internal health checks
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user