diff --git a/Gopkg.lock b/Gopkg.lock index d9597d4..709beac 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,6 +2,15 @@ [[projects]] + digest = "1:b16fbfbcc20645cb419f78325bb2e85ec729b338e996a228124d68931a6f2a37" + name = "github.com/BurntSushi/toml" + packages = ["."] + pruneopts = "UT" + revision = "b26d9c308763d68093482582cea63d69be07a0f0" + version = "v0.3.0" + +[[projects]] + digest = "1:e117797d441bd678eb4601ba83546855365d4f58806b698d2b1b2d16c9ed16fa" name = "github.com/coreos/etcd" packages = [ "auth/authpb", @@ -9,89 +18,113 @@ "etcdserver/api/v3rpc/rpctypes", "etcdserver/etcdserverpb", "mvcc/mvccpb", - "pkg/types" + "pkg/types", ] + pruneopts = "UT" revision = "e348b1aedd9167360c466ae98f7343d3e22281f8" version = "v3.3.3" [[projects]] + digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" name = "github.com/davecgh/go-spew" packages = ["spew"] + pruneopts = "UT" revision = "346938d642f2ec3594ed81d874461961cd0faa76" version = "v1.1.0" [[projects]] + digest = "1:ca82a3b99694824c627573c2a76d0e49719b4a9c02d1d85a2ac91f1c1f52ab9b" name = "github.com/fatih/structs" packages = ["."] + pruneopts = "UT" revision = "a720dfa8df582c51dee1b36feabb906bde1588bd" version = "v1.0" [[projects]] + digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" name = "github.com/go-yaml/yaml" packages = ["."] + pruneopts = "UT" revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" version = "v2.2.1" [[projects]] + digest = "1:8f13f978d35181fada0ea713c14a224f2b329fa91c13438b2811331ecd8b16e1" name = "github.com/gogo/protobuf" packages = [ "gogoproto", "proto", - "protoc-gen-gogo/descriptor" + "protoc-gen-gogo/descriptor", ] + pruneopts = "UT" revision = "1adfc126b41513cc696b209667c8656ea7aac67c" version = "v1.0.0" [[projects]] + digest = "1:8caffcd8995b0eae7d2c18b2baefabef331bb05b1e16ed2b26b732c3349e6989" name = "github.com/golang/protobuf" packages = [ "proto", "ptypes", "ptypes/any", "ptypes/duration", - "ptypes/timestamp" + "ptypes/timestamp", ] + pruneopts = "UT" revision = "925541529c1fa6821df4e44ce2723319eb2be768" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:29a5ab9fa9e845fd8e8726f31b187d710afd271ef1eb32085fe3d604b7e06382" name = "github.com/golang/snappy" packages = ["."] + pruneopts = "UT" revision = "553a641470496b2327abcac10b36396bd98e45c9" [[projects]] + digest = "1:7d9085638f210faa86720b5fe8c4cd9303edb853ed93929852a4384a4e6c956f" name = "github.com/hashicorp/consul" packages = ["api"] + pruneopts = "UT" revision = "fb848fc48818f58690db09d14640513aa6bf3c02" version = "v1.0.7" [[projects]] branch = "master" + digest = "1:07671f8997086ed115824d1974507d2b147d1e0463675ea5dbf3be89b1c2c563" name = "github.com/hashicorp/errwrap" packages = ["."] + pruneopts = "UT" revision = "7554cd9344cec97297fa6649b055a8c98c2a1e55" [[projects]] branch = "master" + digest = "1:77cb3be9b21ba7f1a4701e870c84ea8b66e7d74c7c8951c58155fdadae9414ec" name = "github.com/hashicorp/go-cleanhttp" packages = ["."] + pruneopts = "UT" revision = "d5fe4b57a186c716b0e00b8c301cbd9b4182694d" [[projects]] branch = "master" + digest = "1:e5048c5da80697be2fcdecc944e29d2999e01fd7f48b643168443209779f3463" name = "github.com/hashicorp/go-multierror" packages = ["."] + pruneopts = "UT" revision = "b7773ae218740a7be65057fc60b366a49b538a44" [[projects]] branch = "master" + digest = "1:07aebcfa3f8b07d58c5a21ca48c31dd048c94b91c67ba93b26a5f225b5f5fcdb" name = "github.com/hashicorp/go-rootcerts" packages = ["."] + pruneopts = "UT" revision = "6bb64b370b90e7ef1fa532be9e591a81c3493e00" [[projects]] branch = "master" + digest = "1:12247a2e99a060cc692f6680e5272c8adf0b8f572e6bce0d7095e624c958a240" name = "github.com/hashicorp/hcl" packages = [ ".", @@ -102,75 +135,95 @@ "hcl/token", "json/parser", "json/scanner", - "json/token" + "json/token", ] + pruneopts = "UT" revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168" [[projects]] + digest = "1:0dd7b7b01769f9df356dc99f9e4144bdbabf6c79041ea7c0892379c5737f3c44" name = "github.com/hashicorp/serf" packages = ["coordinate"] + pruneopts = "UT" revision = "d6574a5bb1226678d7010325fb6c985db20ee458" version = "v0.8.1" [[projects]] + digest = "1:62acb0602e1fa54327d91ca4290e286b47216f316f1c35fa400a493a0e92af94" name = "github.com/hashicorp/vault" packages = [ "api", "helper/compressutil", "helper/jsonutil", "helper/parseutil", - "helper/strutil" + "helper/strutil", ] + pruneopts = "UT" revision = "7e1fbde40afee241f81ef08700e7987d86fc7242" version = "v0.9.6" [[projects]] branch = "master" + digest = "1:12ae6210bdbdad658a9a67fd95cd9c99f7fdbf12f6d36eaf0af704e69dacf4f5" name = "github.com/mitchellh/go-homedir" packages = ["."] + pruneopts = "UT" revision = "b8bc1bf767474819792c23f32d8286a45736f1c6" [[projects]] branch = "master" + digest = "1:2514da1e59c0a936d8c1e0fbf5592267a3c5893eb4555ce767bb54d149e9cf6e" name = "github.com/mitchellh/mapstructure" packages = ["."] + pruneopts = "UT" revision = "00c29f56e2386353d58c599509e8dc3801b0d716" [[projects]] + digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" name = "github.com/pkg/errors" packages = ["."] + pruneopts = "UT" revision = "645ef00459ed84a119197bfb8d8205042c6df63d" version = "v0.8.0" [[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" name = "github.com/pmezard/go-difflib" packages = ["difflib"] + pruneopts = "UT" revision = "792786c7400a136282c1664665ae0a8db921c6c2" version = "v1.0.0" [[projects]] + digest = "1:0e792eea6c96ec55ff302ef33886acbaa5006e900fefe82689e88d96439dcd84" name = "github.com/ryanuber/go-glob" packages = ["."] + pruneopts = "UT" revision = "572520ed46dbddaed19ea3d9541bdd0494163693" version = "v0.1" [[projects]] branch = "master" + digest = "1:ed1ce33d4bca1c70e0d596f528ecebcfaac8f745003b651a8e73121d1e4189e0" name = "github.com/sethgrid/pester" packages = ["."] + pruneopts = "UT" revision = "ed9870dad3170c0b25ab9b11830cc57c3a7798fb" [[projects]] + digest = "1:7e8d267900c7fa7f35129a2a37596e38ed0f11ca746d6d9ba727980ee138f9f6" name = "github.com/stretchr/testify" packages = [ "assert", - "require" + "require", ] + pruneopts = "UT" revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" version = "v1.2.1" [[projects]] branch = "master" + digest = "1:01ec943e74da037584f3abd30f6007766458e21e48a2d7a99a4627e0ce3f198f" name = "golang.org/x/net" packages = [ "context", @@ -180,11 +233,13 @@ "idna", "internal/timeseries", "lex/httplex", - "trace" + "trace", ] + pruneopts = "UT" revision = "d41e8174641f662c5a2d1c7a5f9e828788eb8706" [[projects]] + digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" name = "golang.org/x/text" packages = [ "collate", @@ -200,18 +255,22 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable" + "unicode/rangetable", ] + pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" + digest = "1:cd018653a358d4b743a9d3bee89e825521f2ab2f2ec0770164bf7632d8d73ab7" name = "google.golang.org/genproto" packages = ["googleapis/rpc/status"] + pruneopts = "UT" revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200" [[projects]] + digest = "1:bbd9219ca27e0bc3a8d98bb599dff0eab24f39a8c9e519e6faa5b9a17598cc8d" name = "google.golang.org/grpc" packages = [ ".", @@ -237,14 +296,24 @@ "stats", "status", "tap", - "transport" + "transport", ] + pruneopts = "UT" revision = "d11072e7ca9811b1100b80ca0269ac831f06d024" version = "v1.11.3" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "dd119391aa68184558f6ef082ab5f3155d9b87ec9e987c896a34bb9dcabe1bc0" + input-imports = [ + "github.com/BurntSushi/toml", + "github.com/coreos/etcd/clientv3", + "github.com/go-yaml/yaml", + "github.com/hashicorp/consul/api", + "github.com/hashicorp/vault/api", + "github.com/pkg/errors", + "github.com/stretchr/testify/assert", + "github.com/stretchr/testify/require", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index f9feb64..8086b5d 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -25,3 +25,7 @@ [prune] go-tests = true unused-packages = true + +[[constraint]] + name = "github.com/BurntSushi/toml" + version = "0.3.0" diff --git a/README.md b/README.md index b79998f..c254aef 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/backend/file/file.go b/backend/file/file.go index 1feff25..44226fe 100644 --- a/backend/file/file.go +++ b/backend/file/file.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" + "github.com/BurntSushi/toml" "github.com/go-yaml/yaml" "github.com/pkg/errors" ) @@ -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) } diff --git a/backend/file/file_test.go b/backend/file/file_test.go index 6d77f8f..dcced62 100644 --- a/backend/file/file_test.go +++ b/backend/file/file_test.go @@ -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"