61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
polochon "github.com/odwrtw/polochon/lib"
|
|
"github.com/odwrtw/polochon/modules/tmdb"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type Config struct {
|
|
Authorizer AuthorizerConfig `yaml:"authorizer"`
|
|
PGDSN string `yaml:"pgdsn"`
|
|
Port string `yaml:"listen_port"`
|
|
TraktTVClientID string `yaml:"trakttv_client_id"`
|
|
PublicDir string `yaml:"public_dir"`
|
|
|
|
// TODO improve the detailers configurations
|
|
TmdbAPIKey string `yaml:"tmdb_api_key"`
|
|
MovieDetailers []polochon.Detailer
|
|
}
|
|
|
|
type AuthorizerConfig struct {
|
|
Pepper string `yaml:"pepper"`
|
|
Cost int `yaml:"cost"`
|
|
Secret string `yaml:"secret"`
|
|
}
|
|
|
|
func Load(path string) (*Config, error) {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
|
|
cf := &Config{}
|
|
|
|
b, err := ioutil.ReadAll(file)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = yaml.Unmarshal(b, cf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cf.MovieDetailers = []polochon.Detailer{}
|
|
if cf.TmdbAPIKey != "" {
|
|
d, err := tmdb.New(&tmdb.Params{cf.TmdbAPIKey})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cf.MovieDetailers = append(cf.MovieDetailers, d)
|
|
}
|
|
|
|
return cf, nil
|
|
}
|