package config import ( "io/ioutil" "os" polochon "github.com/odwrtw/polochon/lib" polochonConfig "github.com/odwrtw/polochon/lib/configuration" "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) // Config represents the Config of the canape app type Config struct { Authorizer AuthorizerConfig `yaml:"authorizer"` PGDSN string `yaml:"pgdsn"` Port string `yaml:"listen_port"` PublicDir string `yaml:"public_dir"` ImgURLPrefix string `yaml:"img_url_prefix"` PeriodicRefresh PeriodicRefreshConfig `yaml:"periodic_refresh"` MovieExplorers []polochon.Explorer MovieDetailers []polochon.Detailer MovieTorrenters []polochon.Torrenter MovieSearchers []polochon.Searcher ShowExplorers []polochon.Explorer ShowDetailers []polochon.Detailer ShowTorrenters []polochon.Torrenter ShowSearchers []polochon.Searcher } // AuthorizerConfig is the config for the authentication type AuthorizerConfig struct { Pepper string `yaml:"pepper"` Cost int `yaml:"cost"` Secret string `yaml:"secret"` } // PeriodicRefreshConfig is the config for the periodic refresh type PeriodicRefreshConfig struct { Enabled bool `yaml:"enabled"` Interval string `yaml:"interval"` } // Load loads a config file from a path and return a Config object func Load(path string, log *logrus.Entry) (*Config, error) { // Open the file file, err := os.Open(path) if err != nil { return nil, err } defer file.Close() cf := &Config{} polochonCf := &polochonConfig.ConfigFileRoot{} // Read it b, err := ioutil.ReadAll(file) if err != nil { return nil, err } // Unmarshal its content into the Config obj err = yaml.Unmarshal(b, cf) if err != nil { return nil, err } // Unmarshal its content into the polochon.ConfigFileRoot obj err = yaml.Unmarshal(b, polochonCf) if err != nil { return nil, err } // Init all the show torrenters / detailers / searchers / explorers showConf, err := polochonCf.InitShow(log) if err != nil { return nil, err } cf.ShowTorrenters = showConf.Torrenters cf.ShowDetailers = showConf.Detailers cf.ShowSearchers = showConf.Searchers cf.ShowExplorers = showConf.Explorers // Init all the movie torrenters / detailers / searchers / explorers movieConf, err := polochonCf.InitMovie(log) if err != nil { return nil, err } cf.MovieTorrenters = movieConf.Torrenters cf.MovieDetailers = movieConf.Detailers cf.MovieSearchers = movieConf.Searchers cf.MovieExplorers = movieConf.Explorers return cf, nil }