Merge pull request #25 from mkalus/master

Add /health endpoint for health checks.
This commit is contained in:
Pierre Zemb 2019-11-26 16:49:55 +01:00 committed by GitHub
commit 20aeab6b06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -48,6 +48,8 @@ Usage of /goStatic:
Define the user (default "gopher") Define the user (default "gopher")
-enable-basic-auth -enable-basic-auth
Enable basic auth. By default, password are randomly generated. Use --set-basic-auth to set it. 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 -fallback string
Default fallback file. Either absolute for a specific asset (/index.html), or relative to recursively resolve (index.html). Default fallback file. Either absolute for a specific asset (/index.html), or relative to recursively resolve (index.html).
-password-length int -password-length int

View file

@ -5,6 +5,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"net/http" "net/http"
"strconv" "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)") 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.") 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.") 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") 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") defaultUsernameBasicAuth = flag.String("default-user-basic-auth", "gopher", "Define the user")
sizeRandom = flag.Int("password-length", 16, "Size of the randomized password") 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) http.Handle(pathPrefix, handler)
log.Printf("Listening at 0.0.0.0%v %v...", port, pathPrefix) log.Printf("Listening at 0.0.0.0%v %v...", port, pathPrefix)