Skip to content
Open
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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ Viper requires minimal configuration to load config files. Viper currently suppo
* JSON
* TOML
* YAML
* INI
* envfile
* Java Propeties
* Dotenv

> **NOTE (since v1.20):** HCL, Java Properties, and INI were removed from core to reduce
> third-party dependencies. You can still use them by registering codecs from
> [github.com/go-viper/encoding](https://github.com/go-viper/encoding).
> See the [upgrade guide](UPGRADE.md#breaking-hcl-java-properties-ini-removed-from-core) for details.

A single Viper instance only supports a single configuration file, but multiple
paths may be searched for one.
Expand Down
6 changes: 4 additions & 2 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,15 @@ func SetOptions(opts ...Option) {
// can use it in their testing as well.
func Reset() {
v = New()
SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"}
SupportedExts = []string{"json", "toml", "yaml", "yml", "dotenv", "env"}

resetRemote()
}

// SupportedExts are universally supported extensions.
var SupportedExts = []string{"json", "toml", "yaml", "yml", "properties", "props", "prop", "hcl", "tfvars", "dotenv", "env", "ini"}
// Since v1.20, HCL, Java Properties, and INI were removed from core.
// To use them, register a custom codec via [WithCodecRegistry] and append to this list.
var SupportedExts = []string{"json", "toml", "yaml", "yml", "dotenv", "env"}

// OnConfigChange sets the event handler that is called when a config file changes.
func OnConfigChange(run func(in fsnotify.Event)) { v.OnConfigChange(run) }
Expand Down
9 changes: 7 additions & 2 deletions viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ func TestWriteConfig(t *testing.T) {
"json with file extension and mismatch type": {
configName: "c",
inConfigType: "json",
outConfigType: "hcl",
outConfigType: "toml",
fileName: "c.json",
input: jsonExample,
expectedContent: jsonWriteExpected,
Expand Down Expand Up @@ -2462,7 +2462,12 @@ func TestWatchFile(t *testing.T) {
wg.Wait()
// then the config value should have changed
require.NoError(t, err)
assert.Equal(t, "baz", v.Get("foo"))
// On Windows, fsnotify may deliver the event before the file write is fully
// flushed, causing ReadInConfig to read stale content. Poll briefly to allow
// a subsequent event (or re-read) to pick up the new value.
assert.Eventually(t, func() bool {
return v.Get("foo") == "baz"
}, 5*time.Second, 10*time.Millisecond, "expected foo to be \"baz\"")
})

t.Run("link to real file changed (à la Kubernetes)", func(t *testing.T) {
Expand Down