Add /health endpoint for health checks. Can be enabled using --enable-health.

This commit is contained in:
Maximilian Kalus 2019-11-26 13:27:20 +01:00
parent 08d27145aa
commit 7bbf733d98
2 changed files with 10 additions and 0 deletions

View file

@ -48,6 +48,8 @@ Usage of /goStatic:
Define the user (default "gopher")
-enable-basic-auth
Enable basic auth. By default, password are randomly generated. Use --set-basic-auth to set it.
-enable-health
Enable health check endpoint. You can call /health to get a 200 response. Useful for Kubernetes, OpenFaas, etc.
-fallback string
Default fallback file. Either absolute for a specific asset (/index.html), or relative to recursively resolve (index.html).
-password-length int

View file

@ -5,6 +5,7 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"
"strconv"
@ -19,6 +20,7 @@ var (
fallbackPath = flag.String("fallback", "", "Default fallback file. Either absolute for a specific asset (/index.html), or relative to recursively resolve (index.html)")
headerFlag = flag.String("append-header", "", "HTTP response header, specified as `HeaderName:Value` that should be added to all responses.")
basicAuth = flag.Bool("enable-basic-auth", false, "Enable basic auth. By default, password are randomly generated. Use --set-basic-auth to set it.")
healthCheck = flag.Bool("enable-health", false, "Enable health check endpoint. You can call /health to get a 200 response. Useful for Kubernetes, OpenFaas, etc.")
setBasicAuth = flag.String("set-basic-auth", "", "Define the basic auth. Form must be user:password")
defaultUsernameBasicAuth = flag.String("default-user-basic-auth", "gopher", "Define the user")
sizeRandom = flag.Int("password-length", 16, "Size of the randomized password")
@ -90,6 +92,12 @@ func main() {
}
}
if *healthCheck {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Ok")
})
}
http.Handle(pathPrefix, handler)
log.Printf("Listening at 0.0.0.0%v %v...", port, pathPrefix)