diff --git a/cmd/podsync/config.go b/cmd/podsync/config.go index 86c56720..b6880b5f 100644 --- a/cmd/podsync/config.go +++ b/cmd/podsync/config.go @@ -28,7 +28,7 @@ type Config struct { // ID will be used as feed ID in http://podsync.net/{FEED_ID}.xml Feeds map[string]*feed.Config // Tokens is API keys to use to access YouTube/Vimeo APIs. - Tokens map[model.Provider][]string `toml:"tokens"` + Tokens map[model.Provider]StringSlice `toml:"tokens"` // Downloader (youtube-dl) configuration Downloader ytdl.Config `toml:"downloader"` } @@ -149,3 +149,16 @@ func (c *Config) applyDefaults(configPath string) { } } } + +// StringSlice is a toml extension that lets you to specify either a string +// value (a slice with just one element) or a string slice. +type StringSlice []string + +func (s *StringSlice) UnmarshalTOML(v interface{}) error { + if str, ok := v.(string); ok { + *s = []string{str} + return nil + } + + return errors.New("failed to decode string slice field") +} diff --git a/cmd/podsync/config_test.go b/cmd/podsync/config_test.go index fe2dd9e0..de9fd936 100644 --- a/cmd/podsync/config_test.go +++ b/cmd/podsync/config_test.go @@ -16,7 +16,7 @@ import ( func TestLoadConfig(t *testing.T) { const file = ` [tokens] -youtube = ["123"] +youtube = "123" vimeo = ["321", "456"] [server]