Add health endpoint

Adds a health endpoint for the service.
This commit is contained in:
Felix Niederwanger 2023-12-04 22:05:06 +01:00
parent 1b1419961b
commit 932fa7e376
Signed by: phoenix
GPG key ID: 6E77A590E3F6D71C

View file

@ -113,6 +113,8 @@ func main() {
http.Handle("/", http.StripPrefix("/", fs))
http.HandleFunc("/devices", handlerDevices)
http.HandleFunc("/devices.json", handlerDevices)
http.HandleFunc("/health.json", handlerHealth)
http.HandleFunc("/health", handlerHealth)
http.HandleFunc("/locations", handlerLocations)
http.HandleFunc("/devices/", handlerDeviceQuery)
fmt.Println("ot-browser serving: http://" + config.bindAddr)
@ -143,6 +145,12 @@ func (c *Config) ReadFile(filename string) error {
return nil
}
// handlerHealth - health endpoint - writes a health status message to the client
func handlerHealth(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"status":"ok"}`))
}
func handlerDevices(w http.ResponseWriter, r *http.Request) {
devs := make([]string, 0)
for dev := range devices {