Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toml support #43

Merged
merged 3 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 79 additions & 10 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/BurntSushi/toml"
version = "0.3.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Confita is a library that loads configuration from multiple backends and stores
- Environment variables
- JSON files
- Yaml files
- Toml files
- Command line flags
- [etcd](https://github.com/coreos/etcd)
- [Consul](https://www.consul.io/)
Expand Down
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