Add healthz endpoint

git-svn-id: file:///srv/svn/repo/toyohime/trunk@93 922d331f-388e-da47-97a9-ad700dc0b8b9
This commit is contained in:
jonbetti 2018-06-06 16:37:39 +00:00
parent 952a62c7e8
commit faf6868364

View File

@ -3,11 +3,14 @@ Runs a barebones vanity server over HTTP.
Usage
./vanityserver [-index] fqdn [repo file]
./vanityserver [-index] [-nohealthz] fqdn [repo file]
The "-index" flag enables an index page at "/" that lists all repos hosted on
this server.
The "-nohealthz" flag disables the "/healthz" endpoint that returns a 200 OK
when everything is OK.
If repo file is not given, "./repos" is used. The file has the following format:
pkgroot vcsScheme://vcsHost/user/repo
@ -36,7 +39,8 @@ import (
)
var (
showIndex = flag.Bool("index", false, "Show a list of repos at /")
showIndex = flag.Bool("index", false, "Show a list of repos at /")
exposeHealthz = flag.Bool("healthz", true, "Expose a healthz endpoint at /healthz")
)
var host string
@ -129,6 +133,15 @@ Nothing here.
}))
}
func registerHealthz(mux *http.ServeMux) {
mux.Handle("/healthz", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := io.WriteString(w, "OK\r\n")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}))
}
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s fqdn [repos file]", os.Args[0])
@ -155,6 +168,10 @@ func main() {
buildMux(mux, f)
}
if *exposeHealthz {
registerHealthz(mux)
}
srv := &http.Server{
// This should be sufficient.
ReadTimeout: 5 * time.Second,