diff --git a/internal/config/config.go b/internal/config/config.go index 2accc8c3..e6939c2e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,6 +3,7 @@ package config import ( "fmt" "os" + "strconv" "strings" "gopkg.in/yaml.v3" @@ -13,6 +14,7 @@ type Config struct { Database DatabaseConfig `yaml:"database"` Log LogConfig `yaml:"log"` Auth AuthConfig `yaml:"auth"` + Library LibraryConfig `yaml:"library"` } type ServerConfig struct { @@ -40,6 +42,11 @@ type AdminBootstrapConfig struct { Password string `yaml:"password"` } +type LibraryConfig struct { + ScanPaths []string `yaml:"scan_paths"` + ScanOnStartup bool `yaml:"scan_on_startup"` +} + func Default() Config { return Config{ Server: ServerConfig{Address: ":4533"}, @@ -83,4 +90,25 @@ func applyEnv(cfg *Config) { if v, ok := os.LookupEnv("SMARTMUSIC_AUTH_ADMIN_PASSWORD"); ok { cfg.Auth.AdminBootstrap.Password = v } + if v, ok := os.LookupEnv("SMARTMUSIC_LIBRARY_SCAN_PATHS"); ok { + cfg.Library.ScanPaths = splitPaths(v) + } + if v, ok := os.LookupEnv("SMARTMUSIC_LIBRARY_SCAN_ON_STARTUP"); ok { + if b, err := strconv.ParseBool(v); err == nil { + cfg.Library.ScanOnStartup = b + } + } +} + +// splitPaths splits a colon-separated path list, dropping empty entries. +// Colon matches PATH-style Unix conventions; Minstrel ships Linux-only. +func splitPaths(s string) []string { + parts := strings.Split(s, ":") + out := parts[:0] + for _, p := range parts { + if p != "" { + out = append(out, p) + } + } + return out }