Files
gralias/config/config.go
2025-05-29 10:21:47 +03:00

45 lines
1.0 KiB
Go

package config
import (
"fmt"
"log/slog"
"github.com/BurntSushi/toml"
)
type Config struct {
ServerConfig ServerConfig `toml:"SERVICE"`
BaseURL string `toml:"BASE_URL"`
SessionLifetime int `toml:"SESSION_LIFETIME_SECONDS"`
CookieSecret string `toml:"COOKIE_SECRET"`
LLMConfig LLMConfig `toml:"LLM"`
}
type ServerConfig struct {
Host string `toml:"HOST"`
Port string `toml:"PORT"`
}
type LLMConfig struct {
URL string `toml:"URL"`
TOKEN string `toml:"TOKEN"`
}
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 = 30000
config.CookieSecret = "test"
config.ServerConfig.Host = "localhost"
config.ServerConfig.Port = "3000"
}
fmt.Printf("config debug; config.LLMConfig.URL: %s\n", config.LLMConfig.URL)
return config
}