Merge pull request #25 from mkalus/master
Add /health endpoint for health checks.
This commit is contained in:
commit
20aeab6b06
2 changed files with 10 additions and 0 deletions
|
@ -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
|
||||
|
|
8
main.go
8
main.go
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue