1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Switch toml package to github.com/naoina/toml

This commit is contained in:
Maksym Pavlenko
2020-04-20 18:38:52 -07:00
parent df7dc56daf
commit 82bbd02cdf
5 changed files with 43 additions and 22 deletions

4
go.mod
View File

@@ -2,13 +2,15 @@ module github.com/mxpv/podsync
require (
github.com/BrianHicks/finch v0.0.0-20140409222414-419bd73c29ec
github.com/BurntSushi/toml v0.3.1
github.com/dgraph-io/badger v1.6.0
github.com/eduncan911/podcast v1.4.2
github.com/gilliek/go-opml v1.0.0
github.com/golang/mock v1.4.3
github.com/hashicorp/go-multierror v1.0.0
github.com/jessevdk/go-flags v1.4.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/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.1
github.com/silentsokolov/go-vimeo v0.0.0-20190116124215-06829264260c

6
go.sum
View File

@@ -37,9 +37,15 @@ github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGAR
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
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/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View File

@@ -2,11 +2,11 @@ package config
import (
"fmt"
"io/ioutil"
"path/filepath"
"time"
"github.com/BurntSushi/toml"
"github.com/hashicorp/go-multierror"
"github.com/naoina/toml"
"github.com/pkg/errors"
"github.com/mxpv/podsync/pkg/model"
@@ -44,6 +44,11 @@ type Feed struct {
OPML bool `toml:"opml"`
}
type Filters struct {
Title string `toml:"title"`
// More filters to be added here
}
type Custom struct {
CoverArt string `toml:"cover_art"`
Category string `toml:"category"`
@@ -125,10 +130,14 @@ type Config struct {
// LoadConfig loads TOML configuration from a file path
func LoadConfig(path string) (*Config, error) {
config := Config{}
_, err := toml.DecodeFile(path, &config)
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, errors.Wrap(err, "failed to load config file")
return nil, errors.Wrapf(err, "failed to read config file: %s", path)
}
config := Config{}
if err := toml.Unmarshal(data, &config); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal toml")
}
for id, feed := range config.Feeds {
@@ -207,18 +216,3 @@ func (c *Config) applyDefaults(configPath string) {
}
}
}
type Duration struct {
time.Duration
}
func (d *Duration) UnmarshalText(text []byte) error {
var err error
d.Duration, err = time.ParseDuration(string(text))
return err
}
type Filters struct {
Title string `toml:"title"`
// More filters to be added here
}

View File

@@ -44,7 +44,7 @@ self_update = true
config, err := LoadConfig(path)
assert.NoError(t, err)
assert.NotNil(t, config)
require.NotNil(t, config)
assert.Equal(t, "test/data/", config.Server.DataDir)
assert.EqualValues(t, 80, config.Server.Port)

19
pkg/config/toml.go Normal file
View File

@@ -0,0 +1,19 @@
package config
import (
"time"
)
type Duration struct {
time.Duration
}
func (d *Duration) UnmarshalText(text []byte) error {
res, err := time.ParseDuration(string(text))
if err != nil {
return err
}
*d = Duration{res}
return nil
}