Skip to content

Commit

Permalink
Migrate to pelletier/go-toml
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed Jan 2, 2022
1 parent ce2df20 commit db4de62
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ data_dir = "/app/data" # Don't change if you run podsync via docker

# Tokens from `Access tokens` section
[tokens]
youtube = "YOUTUBE_API_TOKEN" # YouTube API Key. See https://developers.google.com/youtube/registering_an_application
youtube = ["YOUTUBE_API_TOKEN"] # YouTube API Key. See https://developers.google.com/youtube/registering_an_application
vimeo = [ # Multiple keys will be rotated.
"VIMEO_API_KEY_1", # Vimeo developer keys. See https://developer.vimeo.com/api/guides/start#generate-access-token
"VIMEO_API_KEY_2"
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ require (
github.com/golang/mock v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/jessevdk/go-flags v1.5.0
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.1
github.com/pelletier/go-toml v1.9.4
github.com/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.1
github.com/silentsokolov/go-vimeo v0.0.0-20190116124215-06829264260c
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,12 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
11 changes: 6 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"io/ioutil"
"path/filepath"
"regexp"
"time"

"github.com/hashicorp/go-multierror"
"github.com/naoina/toml"
"github.com/pelletier/go-toml"
"github.com/pkg/errors"

"github.com/mxpv/podsync/pkg/model"
Expand All @@ -25,7 +26,7 @@ type Feed struct {
// Format is "300ms", "1.5h" or "2h45m".
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
// NOTE: too often update check might drain your API token.
UpdatePeriod Duration `toml:"update_period"`
UpdatePeriod time.Duration `toml:"update_period"`
// Cron expression format is how often to check update
// NOTE: too often update check might drain your API token.
CronSchedule string `toml:"cron_schedule"`
Expand Down Expand Up @@ -137,7 +138,7 @@ type Config struct {
// ID will be used as feed ID in http://podsync.net/{FEED_ID}.xml
Feeds map[string]*Feed
// Tokens is API keys to use to access YouTube/Vimeo APIs.
Tokens map[model.Provider]StringSlice `toml:"tokens"`
Tokens map[model.Provider][]string `toml:"tokens"`
// Downloader (youtube-dl) configuration
Downloader Downloader `toml:"downloader"`
}
Expand Down Expand Up @@ -220,8 +221,8 @@ func (c *Config) applyDefaults(configPath string) {
}

for _, feed := range c.Feeds {
if feed.UpdatePeriod.Duration == 0 {
feed.UpdatePeriod.Duration = model.DefaultUpdatePeriod
if feed.UpdatePeriod == 0 {
feed.UpdatePeriod = model.DefaultUpdatePeriod
}

if feed.Quality == "" {
Expand Down
11 changes: 4 additions & 7 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import (
func TestLoadConfig(t *testing.T) {
const file = `
[tokens]
youtube = "123"
vimeo = [
"321",
"456"
]
youtube = ["123"]
vimeo = ["321", "456"]
[server]
port = 80
Expand Down Expand Up @@ -76,7 +73,7 @@ timeout = 15
assert.True(t, ok)
assert.Equal(t, "https://youtube.com/watch?v=ygIUF678y40", feed.URL)
assert.EqualValues(t, 48, feed.PageSize)
assert.EqualValues(t, Duration{5 * time.Hour}, feed.UpdatePeriod)
assert.EqualValues(t, 5*time.Hour, feed.UpdatePeriod)
assert.EqualValues(t, "audio", feed.Format)
assert.EqualValues(t, "low", feed.Quality)
assert.EqualValues(t, "regex for title here", feed.Filters.Title)
Expand Down Expand Up @@ -142,7 +139,7 @@ data_dir = "/data"
feed, ok := config.Feeds["A"]
require.True(t, ok)

assert.EqualValues(t, feed.UpdatePeriod, Duration{model.DefaultUpdatePeriod})
assert.EqualValues(t, feed.UpdatePeriod, model.DefaultUpdatePeriod)
assert.EqualValues(t, feed.PageSize, 50)
assert.EqualValues(t, feed.Quality, "high")
assert.EqualValues(t, feed.Custom.CoverArtQuality, "high")
Expand Down
41 changes: 0 additions & 41 deletions pkg/config/toml.go

This file was deleted.

0 comments on commit db4de62

Please sign in to comment.