Feat: add models/cache/config
This commit is contained in:
35
config/config.go
Normal file
35
config/config.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user