summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--health.go2
-rw-r--r--main.go12
2 files changed, 13 insertions, 1 deletions
diff --git a/health.go b/health.go
index 2dd2322..043c80f 100644
--- a/health.go
+++ b/health.go
@@ -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
}
diff --git a/main.go b/main.go
index 4851b8a..a383aeb 100644
--- a/main.go
+++ b/main.go
@@ -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)