Files
research/pkg/settings/settings.go
T
2026-11-17 10:28:14 +01:00

56 lines
1.0 KiB
Go

package settings
import (
"fmt"
"os"
"sync"
"github.com/DeanPDX/dotconfig"
)
type Go4lageSettings struct {
OPENROUTER_KEY string `env:"OPENROUTER_KEY"`
BRAVE_KEY string `env:"BRAVE_KEY"`
TARGET_COST_USD float64 `env:"TARGET_COST_USD"`
TARGET_TIME_MINS int `env:"TARGET_TIME_MINS"`
NROFAGENTS int `env:"NROFAGENTS"`
}
var (
mu sync.RWMutex
settings Go4lageSettings
)
func init() {
err := Load(".env")
if err != nil {
fmt.Fprintf(os.Stderr, "warnung: %v\n", err)
}
}
// Load reads the settings file. Call once at startup.
func Load(path string) error {
s, err := dotconfig.FromFileName[Go4lageSettings](path)
if err != nil {
return fmt.Errorf("settings: load %s: %w", path, err)
}
mu.Lock()
settings = s
mu.Unlock()
return nil
}
// Get returns a copy of the current settings.
func Get() Go4lageSettings {
mu.RLock()
defer mu.RUnlock()
return settings
}
// Change modifies the settings under the write lock.
func Change(fn func(s *Go4lageSettings)) {
mu.Lock()
defer mu.Unlock()
fn(&settings)
}