From 1307addddf61c7f811e8f4d360e2368ec7b4b2da Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 23 May 2026 21:15:10 +0200 Subject: Add handlers.go This keeps the HTTP handlers in a separate file which registers the routes in an init() function. The main execution flow is still maintained in a now minimal main.go. --- handlers.go | 19 +++++++++++++++++++ main.go | 14 -------------- 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 handlers.go diff --git a/handlers.go b/handlers.go new file mode 100644 index 0000000..0f6593f --- /dev/null +++ b/handlers.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "net/http" +) + +func init() { + router.HandleFunc("/", hello) + router.HandleFunc("/version", version) +} + +func hello(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "Hello world!") +} + +func version(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, versionTxt) +} diff --git a/main.go b/main.go index eeb9dc3..d9c4580 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( _ "embed" - "fmt" "log" "os" "os/signal" @@ -23,11 +22,6 @@ const ( var versionTxt string var router *mux.Router = mux.NewRouter() -func init() { - router.HandleFunc("/", hello) - router.HandleFunc("/version", version) -} - func main() { run() } @@ -49,14 +43,6 @@ func run() { await(syscall.SIGTERM, syscall.SIGINT) } -func hello(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Hello world!") -} - -func version(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, versionTxt) -} - func await(signals ...syscall.Signal) { listener := make(chan os.Signal, 1) for _, s := range signals { -- cgit v1.3