Feat: add models/cache/config

This commit is contained in:
Grail Finder
2025-05-02 09:06:17 +03:00
parent dbc87d7b9b
commit acaf4af4ce
13 changed files with 554 additions and 1 deletions

35
config/config.go Normal file
View File

@ -0,0 +1,35 @@
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
}