From 0d749eb73262d271f673c70e2ebbaaf66812718e Mon Sep 17 00:00:00 2001 From: Jelmer Snoeck Date: Wed, 6 Jan 2016 17:03:31 +0000 Subject: [PATCH] DebugHandler: add default health checker. By using a DefaultHealthChecker - as with a DefaultName, DefaultServer, ... - it is possible to overwrite the default implementation. This means we can now do extra actions in our health check that is necessary for the applications specific needs. --- server/debug_handler.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/debug_handler.go b/server/debug_handler.go index 3ede5a04..2e25c893 100644 --- a/server/debug_handler.go +++ b/server/debug_handler.go @@ -5,7 +5,15 @@ import ( "golang.org/x/net/context" ) -type Debug struct{} +type ( + HealthChecker interface { + Health(ctx context.Context, req *health.Request, rsp *health.Response) error + } + + Debug struct{} +) + +var DefaultHealthChecker HealthChecker = new(Debug) func (d *Debug) Health(ctx context.Context, req *health.Request, rsp *health.Response) error { rsp.Status = "ok" @@ -13,5 +21,5 @@ func (d *Debug) Health(ctx context.Context, req *health.Request, rsp *health.Res } func registerHealthChecker(s Server) { - s.Handle(s.NewHandler(&Debug{})) + s.Handle(s.NewHandler(DefaultHealthChecker)) }