diff options
| -rw-r--r-- | health.go | 2 | ||||
| -rw-r--r-- | main.go | 12 |
2 files changed, 13 insertions, 1 deletions
@@ -93,7 +93,7 @@ func (hs healthStatus) String() string { result := sb.String() if result == "" { - return "OK: all is fine" + return "OK: all is fine\n" } return result } @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "log" "net/http" ) @@ -9,19 +10,30 @@ import ( func main() { listenAddr := flag.String("listenAddr", "localhost:8080", "The listen address") dataDir := flag.String("dataDir", "data", "The data directory") + health := newHealthStatus() + + http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, health.String()) + }) http.HandleFunc("/submit", func(w http.ResponseWriter, r *http.Request) { if err := handleSubmit(w, r, *dataDir); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Println(err) + health.set(critical, "submitHandler", err.Error()) + return } + health.clear("submitHandler") }) http.HandleFunc("/list", func(w http.ResponseWriter, r *http.Request) { if err := handleList(w, r, *dataDir); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) log.Println(err) + health.set(critical, "listHandler", err.Error()) + return } + health.clear("listHandler") }) log.Println("Server is starting on ", *listenAddr) |
