DefaultMux should only register the first time

This commit is contained in:
Clayton Coleman 2015-05-16 16:11:24 -04:00
parent 1f628f2340
commit c54097d96c

View File

@ -20,6 +20,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"net/http" "net/http"
"sync"
) )
// HealthzChecker is a named healthz check. // HealthzChecker is a named healthz check.
@ -28,9 +29,13 @@ type HealthzChecker interface {
Check(req *http.Request) error Check(req *http.Request) error
} }
var defaultHealthz = sync.Once{}
// DefaultHealthz installs the default healthz check to the http.DefaultServeMux. // DefaultHealthz installs the default healthz check to the http.DefaultServeMux.
func DefaultHealthz(checks ...HealthzChecker) { func DefaultHealthz(checks ...HealthzChecker) {
defaultHealthz.Do(func() {
InstallHandler(http.DefaultServeMux, checks...) InstallHandler(http.DefaultServeMux, checks...)
})
} }
// PingHealthz returns true automatically when checked // PingHealthz returns true automatically when checked