diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-05-12 11:21:41 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-05-12 11:22:01 -0400 |
| commit | 18b8e0e201ecfafce937c781999883ceeba69ce6 (patch) | |
| tree | 09a77392069b6b47cd6b2c04678f0b6b0b7340ec /cmd/mi/main.go | |
| parent | c1a685f81d936fe87673126b9318c78fa21bda94 (diff) | |
| download | x-18b8e0e201ecfafce937c781999883ceeba69ce6.tar.xz x-18b8e0e201ecfafce937c781999883ceeba69ce6.zip | |
cmd/mi: kubernetes manifest
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cmd/mi/main.go')
| -rw-r--r-- | cmd/mi/main.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/cmd/mi/main.go b/cmd/mi/main.go index a904a9b..069abfc 100644 --- a/cmd/mi/main.go +++ b/cmd/mi/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "log/slog" "net/http" "os" @@ -15,8 +16,9 @@ import ( ) var ( - bind = flag.String("bind", ":8080", "HTTP bind address") - dbLoc = flag.String("db-loc", "./var/data.db", "") + bind = flag.String("bind", ":8080", "HTTP bind address") + dbLoc = flag.String("db-loc", "./var/data.db", "") + internalBind = flag.String("internal-bind", ":9195", "HTTP internal routes bind address") ) func main() { @@ -45,6 +47,20 @@ func main() { i := &Importer{db: db} i.Mount(mux) + mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + if err := db.Exec("select 1+1").Error; err != nil { + http.Error(w, "database not healthy", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusOK) + fmt.Fprintln(w, "OK") + }) + + go func() { + slog.Info("starting internal server", "bind", *internalBind) + slog.Error("internal server stopped", "err", http.ListenAndServe(*internalBind, nil)) + }() + slog.Info("starting server", "bind", *bind) slog.Error("server stopped", "err", http.ListenAndServe(*bind, mux)) } |
