Files
zurg/internal/config/load.go
2023-11-07 18:32:30 +01:00

52 lines
1.1 KiB
Go

package config
import (
"fmt"
"os"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"gopkg.in/yaml.v3"
)
type ConfigInterface interface {
GetVersion() string
GetToken() string
GetNumOfWorkers() int
GetRefreshEverySeconds() int
GetCacheTimeHours() int
EnableRepair() bool
GetHost() string
GetPort() string
GetDirectories() []string
MeetsConditions(directory, torrentID, torrentName string, fileNames []string) bool
GetOnLibraryUpdate() string
GetNetworkBufferSize() int
GetMountPoint() string
EnableRetainFolderNameExtension() bool
}
func LoadZurgConfig(filename string) (ConfigInterface, error) {
rlog := logutil.NewLogger()
log := rlog.Named("config")
log.Debug("Loading config file ", filename)
content, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var initialConfig ZurgConfig
if err := yaml.Unmarshal(content, &initialConfig); err != nil {
return nil, err
}
switch initialConfig.Version {
case "v1":
log.Debug("Detected config version: v1")
return loadV1Config(content)
default:
return nil, fmt.Errorf("invalid config version: %s", initialConfig.Version)
}
}