Skip to content

Commit

Permalink
toml support
Browse files Browse the repository at this point in the history
  • Loading branch information
b0000000000000t committed Sep 20, 2018
1 parent 5e2be45 commit 06ce79e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"

"github.com/BurntSushi/toml"
"github.com/go-yaml/yaml"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -47,6 +48,8 @@ func (b *Backend) Unmarshal(ctx context.Context, to interface{}) error {
fallthrough
case ".yaml":
err = yaml.NewDecoder(f).Decode(to)
case ".toml":
_, err = toml.DecodeReader(f, to)
default:
err = errors.Errorf("unsupported extension \"%s\"", ext)
}
Expand Down
11 changes: 11 additions & 0 deletions backend/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ func TestFileBackend(t *testing.T) {
testLoad(t, path)
})

t.Run("TOML", func(t *testing.T) {
path, cleanup := createTempFile(t, "config.toml",
`name = "some name"
age = 10
timeout = 10
`)
defer cleanup()

testLoad(t, path)
})

t.Run("Unsupported extension", func(t *testing.T) {
path, cleanup := createTempFile(t, "config.xml", `{
"name": "some name"
Expand Down

0 comments on commit 06ce79e

Please sign in to comment.