Make use of the config

This commit is contained in:
Imbus 2024-02-28 08:39:42 +01:00
parent 34c0712825
commit 2349fad4f4

View file

@ -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)
}