mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 18:53:43 -04:00
Start http handler on port 8080 and return OK. Also add some documentation fixes for the prometheus middleware.
39 lines
550 B
Go
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"
|
|
)
|