add RegisterCheck web server option for internal health checks
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		| @@ -25,6 +25,9 @@ type Options struct { | ||||
| 	RegisterTTL      time.Duration | ||||
| 	RegisterInterval time.Duration | ||||
|  | ||||
| 	// RegisterCheck runs a check function before registering the service | ||||
| 	RegisterCheck func(context.Context) error | ||||
|  | ||||
| 	Server  *http.Server | ||||
| 	Handler http.Handler | ||||
|  | ||||
| @@ -62,6 +65,10 @@ func newOptions(opts ...Option) Options { | ||||
| 		o(&opt) | ||||
| 	} | ||||
|  | ||||
| 	if opt.RegisterCheck == nil { | ||||
| 		opt.RegisterCheck = DefaultRegisterCheck | ||||
| 	} | ||||
|  | ||||
| 	return opt | ||||
| } | ||||
|  | ||||
| @@ -225,3 +232,10 @@ func StaticDir(d string) Option { | ||||
| 		o.StaticDir = d | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // RegisterCheck run func before registry service | ||||
| func RegisterCheck(fn func(context.Context) error) Option { | ||||
| 	return func(o *Options) { | ||||
| 		o.RegisterCheck = fn | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user