refactor: clean up and add example config and pattern

This commit is contained in:
Patryk Hegenberg 2026-01-18 17:51:23 +01:00
parent 07798189a2
commit 17723de72f
10 changed files with 96 additions and 430 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"log/slog"
"os"
"regexp"
"time"
@ -156,7 +157,7 @@ func setConfigDefaults() {
viper.SetDefault("export.retry_backoff", "5s")
viper.SetDefault("export.health_check_interval", "60s")
viper.SetDefault("localstorage.enabled", true)
viper.SetDefault("localstorage.db_path", "./tixel_watch.db")
viper.SetDefault("localstorage.db_path", "./watch.db")
viper.SetDefault("localstorage.rotation.max_size_bytes", int64(100*1024*1024))
viper.SetDefault("localstorage.rotation.max_age_hours", 24)
viper.SetDefault("localstorage.rotation.max_files", 7)
@ -171,9 +172,13 @@ func setConfigDefaults() {
}
func LoadConfig() (*Config, error) {
home, err := os.UserConfigDir()
if err != nil {
return nil, fmt.Errorf("unable to get user config dir: %w", err)
}
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.AddConfigPath("/opt/tixel/tixel-watch/")
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
setConfigDefaults()