more initial changes
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type WatchConfig struct {
|
||||
Dirs []string `yaml:"dirs"`
|
||||
StableSeconds int `yaml:"stable_seconds"`
|
||||
IncludeExt []string `yaml:"include_ext"`
|
||||
ExcludeExt []string `yaml:"exclude_ext"`
|
||||
}
|
||||
|
||||
type StructureConfig struct {
|
||||
MoviesDir string `yaml:"movies_dir"`
|
||||
TVDir string `yaml:"tv_dir"`
|
||||
@@ -13,24 +22,75 @@ type StructureConfig struct {
|
||||
AutoCreate bool `yaml:"auto_create"`
|
||||
}
|
||||
|
||||
type WatchConfig struct {
|
||||
Dirs []string `yaml:"dirs"`
|
||||
type RsyncTarget struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
DestBase string `yaml:"dest_base"`
|
||||
ExtraArgs []string `yaml:"extra_args"`
|
||||
}
|
||||
|
||||
type SyncConfig struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
RsyncBinary string `yaml:"rsync_binary"`
|
||||
Targets []RsyncTarget `yaml:"targets"`
|
||||
}
|
||||
|
||||
type NotifierEndpoint struct {
|
||||
Name string `yaml:"name"`
|
||||
Method string `yaml:"method"`
|
||||
URL string `yaml:"url"`
|
||||
Headers map[string]string `yaml:"headers"`
|
||||
Body string `yaml:"body"`
|
||||
}
|
||||
|
||||
type NotifierConfig struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Endpoints []NotifierEndpoint `yaml:"endpoints"`
|
||||
}
|
||||
|
||||
type LoggingConfig struct {
|
||||
Level string `yaml:"level"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Watch WatchConfig `yaml:"watch"`
|
||||
Structure StructureConfig `yaml:"structure"`
|
||||
Sync SyncConfig `yaml:"sync"`
|
||||
Notifier NotifierConfig `yaml:"notifier"`
|
||||
Logging LoggingConfig `yaml:"logging"`
|
||||
}
|
||||
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
func Load(path string) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("read config: %w", err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("parse yaml: %w", err)
|
||||
}
|
||||
|
||||
if cfg.Watch.StableSeconds <= 0 {
|
||||
cfg.Watch.StableSeconds = 15
|
||||
}
|
||||
|
||||
if cfg.Sync.RsyncBinary == "" {
|
||||
cfg.Sync.RsyncBinary = "/usr/bin/rsync"
|
||||
}
|
||||
|
||||
if cfg.Structure.MoviesDir == "" {
|
||||
cfg.Structure.MoviesDir = "/srv/media/incoming/movies"
|
||||
}
|
||||
if cfg.Structure.TVDir == "" {
|
||||
cfg.Structure.TVDir = "/srv/media/incoming/tv"
|
||||
}
|
||||
if cfg.Structure.MiscDir == "" {
|
||||
cfg.Structure.MiscDir = "/srv/media/incoming/misc"
|
||||
}
|
||||
if cfg.Structure.UnknownDir == "" {
|
||||
cfg.Structure.UnknownDir = "/srv/media/incoming/unknown"
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
|
||||
Reference in New Issue
Block a user