Config parsing and database api changes

This commit is contained in:
Imbus 2024-02-28 03:21:13 +01:00
parent 06632c16da
commit e1cd596c13
3 changed files with 81 additions and 28 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"ttime/internal/config"
"ttime/internal/database"
_ "github.com/mattn/go-sqlite3"
@ -40,7 +41,15 @@ func handler(w http.ResponseWriter, r *http.Request) {
}
func main() {
database.DbConnect()
conf, err := config.ReadConfigFromFile("config.toml")
if err != nil {
conf = config.NewConfig()
conf.WriteConfigToFile("config.toml")
}
println(conf)
database.DbConnect("db.sqlite3")
b := &ButtonState{PressCount: 0}
// Mounting the handlers
@ -54,7 +63,7 @@ func main() {
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")
println("Press Ctrl+C to stop the server")
err := http.ListenAndServe(":8080", nil)
err = http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}