Files
golias/config/config.go
2025-05-02 09:06:17 +03:00

36 lines
803 B
Go

package config
import (
"log/slog"
"github.com/BurntSushi/toml"
)
type Config struct {
ServerConfig ServerConfig `toml:"SERVICE"`
BaseURL string `toml:"BASE_URL"`
SessionLifetime int `toml:"SESSION_LIFETIME_SECONDS"`
DBURI string `toml:"DBURI"`
CookieSecret string `toml:"COOKIE_SECRET"`
}
type ServerConfig struct {
Host string `toml:"HOST"`
Port string `toml:"PORT"`
}
func LoadConfigOrDefault(fn string) *Config {
if fn == "" {
fn = "config.toml"
}
config := &Config{}
_, err := toml.DecodeFile(fn, &config)
if err != nil {
slog.Warn("failed to read config from file, loading default", "error", err)
config.BaseURL = "https://localhost:3000"
config.SessionLifetime = 300
config.CookieSecret = "test"
}
return config
}