From 2349fad4f49ef8ee934855d7f4f2fc313a22c297 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 28 Feb 2024 08:39:42 +0100 Subject: [PATCH] Make use of the config --- backend/cmd/main.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index bb71e31..ea8d968 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -47,9 +47,11 @@ func main() { conf.WriteConfigToFile("config.toml") } - println(conf) + // Pretty print the current config + str, _ := json.MarshalIndent(conf, "", " ") + fmt.Println(string(str)) - database.DbConnect("db.sqlite3") + database.DbConnect(conf.DbPath) b := &ButtonState{PressCount: 0} // Mounting the handlers @@ -58,12 +60,14 @@ func main() { http.HandleFunc("/hello", handler) http.HandleFunc("/api/button", b.pressHandler) - // Start the server on port 8080 - println("Currently listening on http://localhost:8080") - println("Visit http://localhost:8080/hello to see the hello handler in action") - println("Visit http://localhost:8080/button to see the button handler in action") + // Construct a server URL + server_url := fmt.Sprintf(":%d", conf.Port) + + println("Server running on port", conf.Port) + println("Visit http://localhost" + server_url) println("Press Ctrl+C to stop the server") - err = http.ListenAndServe(":8080", nil) + + err = http.ListenAndServe(server_url, nil) if err != nil { panic(err) }