feat(config): supports toml config files

This commit is contained in:
Anhgelus Morhtuuzh 2025-03-03 11:05:58 +01:00
parent 9ea75094de
commit 69ab8022bd
No known key found for this signature in database
GPG key ID: CAD341EFA92DDDE5
4 changed files with 58 additions and 53 deletions

12
main.go
View file

@ -4,10 +4,12 @@ import (
"embed"
"encoding/json"
"flag"
"github.com/BurntSushi/toml"
"github.com/anhgelus/golatt"
"log/slog"
"net/http"
"os"
"strings"
)
var (
@ -49,8 +51,15 @@ func main() {
if err != nil {
panic(err)
}
var cfg Config
err = json.Unmarshal(b, &cfg)
if strings.HasSuffix(configPath, ".json") {
err = json.Unmarshal(b, &cfg)
} else if strings.HasSuffix(configPath, ".toml") {
err = toml.Unmarshal(b, &cfg)
} else {
panic("config file must be .json or .toml")
}
if err != nil {
panic(err)
}
@ -58,6 +67,7 @@ func main() {
if err != nil {
panic(err)
}
var g *golatt.Golatt
if dev {
g = golatt.New(golatt.UsableEmbedFS("templates", templates), os.DirFS("public"), os.DirFS("dist"))