mirror of
https://github.com/spf13/viper
synced 2025-05-06 12:17:18 +00:00
This patch makes TOML support optional, disabling it by default. To enable support include the Golang build tag `toml`. For example, the following command builds Viper without TOML support: $ go build Whereas this command will build Viper, along with support for parsing TOML: $ go build -tags toml The reason for making TOML optional is due to the dependency upon the BurntSushi package that is used to unmarshal TOML content. The package is licensed under the WTFPL license (http://www.wtfpl.net/) and incompatible with the Kubernetes project. Pull requests submitted to K8 that transitively include a dependency upon packages licensed under the WTFPL license are denied. To this end, until such time an alternative package is deemed acceptable for parsing TOML content, this patch would make TOML an optional component of Viper, enabled only when explicitly requested via the build tag `toml`.
37 lines
747 B
Go
37 lines
747 B
Go
// +build toml
|
|
|
|
// Copyright © 2014 Steve Francia <spf@spf13.com>.
|
|
//
|
|
// Use of this source code is governed by an MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package viper
|
|
|
|
import (
|
|
"bytes"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var tomlExample = []byte(`
|
|
title = "TOML Example"
|
|
|
|
[owner]
|
|
organization = "MongoDB"
|
|
Bio = "MongoDB Chief Developer Advocate & Hacker at Large"
|
|
dob = 1979-05-27T07:32:00Z # First class dates? Why not?`)
|
|
|
|
func initTOML(reset bool) {
|
|
if reset {
|
|
Reset()
|
|
}
|
|
SetConfigType("toml")
|
|
r := bytes.NewReader(tomlExample)
|
|
unmarshalReader(r, v.config)
|
|
}
|
|
|
|
func assertConfigValue(t *testing.T, v *Viper) {
|
|
assert.Equal(t, `value is `+path.Base(v.configPaths[0]), v.GetString(`key`))
|
|
}
|