Files
coredns/middleware/health/health.go
Miek Gieben 68171c7a63 A health middleware
Start http handler on port 8080 and return OK. Also add some

documentation fixes for the prometheus middleware.
2016-04-06 09:21:46 +01:00

39 lines
550 B
Go

package health
import (
"io"
"log"
"net/http"
"sync"
)
var once sync.Once
type Health struct {
Addr string
}
func health(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, ok)
}
func (h Health) ListenAndServe() error {
if h.Addr == "" {
h.Addr = defAddr
}
once.Do(func() {
http.HandleFunc("/health", health)
go func() {
if err := http.ListenAndServe(h.Addr, nil); err != nil {
log.Printf("[ERROR] Failed to start health handler: %s", err)
}
}()
})
return nil
}
const (
ok = "OK"
defAddr = ":8080"
)