Skip to content

Commit 82bbd02

Browse files
committed
Switch toml package to github.com/naoina/toml
1 parent df7dc56 commit 82bbd02

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ module github.com/mxpv/podsync
22

33
require (
44
github.com/BrianHicks/finch v0.0.0-20140409222414-419bd73c29ec
5-
github.com/BurntSushi/toml v0.3.1
65
github.com/dgraph-io/badger v1.6.0
76
github.com/eduncan911/podcast v1.4.2
87
github.com/gilliek/go-opml v1.0.0
98
github.com/golang/mock v1.4.3
109
github.com/hashicorp/go-multierror v1.0.0
1110
github.com/jessevdk/go-flags v1.4.0
11+
github.com/kylelemons/godebug v1.1.0 // indirect
12+
github.com/naoina/go-stringutil v0.1.0 // indirect
13+
github.com/naoina/toml v0.1.1
1214
github.com/pkg/errors v0.9.1
1315
github.com/robfig/cron/v3 v3.0.1
1416
github.com/silentsokolov/go-vimeo v0.0.0-20190116124215-06829264260c

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGAR
3737
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
3838
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
3939
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
40+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
41+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
4042
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
4143
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
4244
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
45+
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
46+
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
47+
github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
48+
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
4349
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
4450
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
4551
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

pkg/config/config.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package config
22

33
import (
44
"fmt"
5+
"io/ioutil"
56
"path/filepath"
6-
"time"
77

8-
"github.com/BurntSushi/toml"
98
"github.com/hashicorp/go-multierror"
9+
"github.com/naoina/toml"
1010
"github.com/pkg/errors"
1111

1212
"github.com/mxpv/podsync/pkg/model"
@@ -44,6 +44,11 @@ type Feed struct {
4444
OPML bool `toml:"opml"`
4545
}
4646

47+
type Filters struct {
48+
Title string `toml:"title"`
49+
// More filters to be added here
50+
}
51+
4752
type Custom struct {
4853
CoverArt string `toml:"cover_art"`
4954
Category string `toml:"category"`
@@ -125,10 +130,14 @@ type Config struct {
125130

126131
// LoadConfig loads TOML configuration from a file path
127132
func LoadConfig(path string) (*Config, error) {
128-
config := Config{}
129-
_, err := toml.DecodeFile(path, &config)
133+
data, err := ioutil.ReadFile(path)
130134
if err != nil {
131-
return nil, errors.Wrap(err, "failed to load config file")
135+
return nil, errors.Wrapf(err, "failed to read config file: %s", path)
136+
}
137+
138+
config := Config{}
139+
if err := toml.Unmarshal(data, &config); err != nil {
140+
return nil, errors.Wrap(err, "failed to unmarshal toml")
132141
}
133142

134143
for id, feed := range config.Feeds {
@@ -207,18 +216,3 @@ func (c *Config) applyDefaults(configPath string) {
207216
}
208217
}
209218
}
210-
211-
type Duration struct {
212-
time.Duration
213-
}
214-
215-
func (d *Duration) UnmarshalText(text []byte) error {
216-
var err error
217-
d.Duration, err = time.ParseDuration(string(text))
218-
return err
219-
}
220-
221-
type Filters struct {
222-
Title string `toml:"title"`
223-
// More filters to be added here
224-
}

pkg/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ self_update = true
4444

4545
config, err := LoadConfig(path)
4646
assert.NoError(t, err)
47-
assert.NotNil(t, config)
47+
require.NotNil(t, config)
4848

4949
assert.Equal(t, "test/data/", config.Server.DataDir)
5050
assert.EqualValues(t, 80, config.Server.Port)

pkg/config/toml.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package config
2+
3+
import (
4+
"time"
5+
)
6+
7+
type Duration struct {
8+
time.Duration
9+
}
10+
11+
func (d *Duration) UnmarshalText(text []byte) error {
12+
res, err := time.ParseDuration(string(text))
13+
if err != nil {
14+
return err
15+
}
16+
17+
*d = Duration{res}
18+
return nil
19+
}

0 commit comments

Comments
 (0)