Skip to content
Extraits de code Groupes Projets
Valider 11de38ab rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Instanciate readers from conf

parent d8f3e276
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -13,12 +13,32 @@ import ( ...@@ -13,12 +13,32 @@ import (
) )
type config struct { type config struct {
Db bot.DbParams Db bot.DbParams
Transport map[string]transportParams `yaml:"transports"` Transports map[string]transportParams `yaml:"transports"`
Readers map[string]readerParams `yaml:"sites"`
} }
type readerParams map[string]interface{}
type transportParams map[string]interface{} type transportParams map[string]interface{}
func getReader(name string, config map[string]interface{}) site.Reader {
var err error
var reader site.Reader
switch name {
case "youtube":
reader, err = site.NewYoutube(config["api_key"].(string))
default:
log.Fatalf("Unsupported site '%s'", name)
}
if err != nil {
log.Fatal(err)
}
return reader
}
func startTransport(name string, config transportParams, factory bot.Factory) chan bool { func startTransport(name string, config transportParams, factory bot.Factory) chan bool {
transportType, ok := config["type"] transportType, ok := config["type"]
if !ok { if !ok {
...@@ -54,19 +74,18 @@ func main() { ...@@ -54,19 +74,18 @@ func main() {
var config config var config config
err = yaml.Unmarshal(file, &config) err = yaml.Unmarshal(file, &config)
quit := make(map[string](chan bool)) quit := make(map[string](chan bool))
var readers []site.Reader
youtube, err := site.NewYoutube("AIzaSyD32EU9lb9cnNcEaSUBKCkKodk6rjl3HYc") for name, readerCfg := range config.Readers {
if err != nil { reader := getReader(name, readerCfg)
log.Fatal(err) readers = append(readers, reader)
}
readers := []site.Reader{
//&site.Youtube{},
youtube,
} }
factory := bot.NewPlayBotFactory(config.Db, readers) factory := bot.NewPlayBotFactory(config.Db, readers)
for name, config := range config.Transport { for name, config := range config.Transports {
c := startTransport(name, config, factory) c := startTransport(name, config, factory)
quit[name] = c quit[name] = c
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter