tss/app/config.go
2022-04-28 19:24:21 -04:00

49 lines
810 B
Go

package app
import (
"os"
"path"
"gopkg.in/yaml.v3"
)
type FeedCfg struct {
Name string `yaml:"name"`
Channel string `yaml:"channel"`
Rhash string `yaml:"rhash"`
Url string `yaml:"url"`
Cron string `yaml:"cron"`
Proxy string `yaml:"proxy"`
}
type Config struct {
DataDir string `yaml:"data_dir"`
LastSuccessPath string `yaml:"last_loaded_path"`
Feeds []FeedCfg `yaml:"feeds"`
}
func ParseConfig(configPath string) (*Config, error) {
cfg, err := os.ReadFile(configPath)
if err != nil {
return nil, err
}
c := Config{}
err = yaml.Unmarshal(cfg, &c)
if err != nil {
return nil, err
}
if c.DataDir == "" {
c.DataDir = "."
}
if c.LastSuccessPath == "" {
c.LastSuccessPath = path.Join(c.DataDir, "last_success.yml")
}
return &c, nil
}