diff options
author | Lizzy Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-10 01:25:22 -0700 |
---|---|---|
committer | Lizzy Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-10 01:25:22 -0700 |
commit | 11155128178ff3d8ea803a70dd7749e594b247a9 (patch) | |
tree | 23bbc8abfa3c9a51b48b3d670e59332a10a9d8f3 /html/fruitvote/main.go | |
parent | f2bf6e326bb0a5c3363b1fe3891a841dec644948 (diff) | |
download | tilde.club-11155128178ff3d8ea803a70dd7749e594b247a9.tar.gz tilde.club-11155128178ff3d8ea803a70dd7749e594b247a9.zip |
remove bad database flag, bad curl options, and add sigint listener
Diffstat (limited to 'html/fruitvote/main.go')
-rw-r--r-- | html/fruitvote/main.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/html/fruitvote/main.go b/html/fruitvote/main.go index 73c1c17..b41c88f 100644 --- a/html/fruitvote/main.go +++ b/html/fruitvote/main.go @@ -3,11 +3,14 @@ package main import ( "flag" "fmt" + "log" "net" "net/http" "os" "os/exec" + "os/signal" "strings" + "syscall" ) func indexHandler(w http.ResponseWriter, r *http.Request) { @@ -15,6 +18,11 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, this is a Unix socket HTTP server in Go!")) } +func healthCheckHandler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("healthy")) +} + func main() { socketPath, users := getArgs() os.Remove(socketPath) @@ -24,6 +32,17 @@ func main() { panic(err) } os.Chmod(socketPath, 0700) + + sigc := make(chan os.Signal, 1) + signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM) + go func(c chan os.Signal) { + // Wait for a SIGINT or SIGKILL: + sig := <-c + log.Printf("Caught signal %s: shutting down.", sig) + + listener.Close() + os.Exit(0) + }(sigc) defer listener.Close() for _, user := range strings.Split(users, ",") { @@ -32,6 +51,7 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/", indexHandler) + mux.HandleFunc("/health", healthCheckHandler) http.Serve(listener, mux) } |