add basic healthcheck

This commit is contained in:
Jakub Sokołowski 2018-06-15 17:07:48 +02:00
parent 782812de4b
commit 17924e7bb6
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
1 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"net/http"
"time"
@ -36,10 +37,17 @@ func init() {
type Stats struct {
}
// For verifying the service is up
func healthHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "OK")
}
// NewStats returns new empty Stats object.
func NewStats(statsPort string) *Stats {
go func() {
http.Handle("/metrics", promhttp.Handler())
// Add most trivial healthcheck
http.HandleFunc("/health", healthHandler)
log.Fatal(http.ListenAndServe(statsPort, nil))
}()
return &Stats{}