Skip to content

Commit

Permalink
Allow specify string as API key
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed Jan 2, 2022
1 parent 142b0e0 commit 43c44fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion cmd/podsync/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion cmd/podsync/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestLoadConfig(t *testing.T) {
const file = `
[tokens]
youtube = ["123"]
youtube = "123"
vimeo = ["321", "456"]
[server]
Expand Down

0 comments on commit 43c44fc

Please sign in to comment.