* Add DocBlock to WatchConfig
Added a small description of the WatchConfig().
So that you can understand in the ide why you could use it.
* Update viper.go
* update viper.go
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Co-authored-by: Márk Sági-Kazár <sagikazarmark@users.noreply.github.com>
Co-authored-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
One might want to write the debug information somewhere other than
Stdout. This patch adss a DebugTo function and method, that accepts
an io.Writer. It changes the original Debug implementation to call
this new function with a default of os.Stdout, which maintains
backward compatibility.
Signed-off-by: Brad P. Crochet <brad@redhat.com>
We have encountered numerous places where it is convenient to have viper return a `uint16` value, especially in combination with the new `netip` package that represents a port correctly as `uint16` rather than just an `int`. cobra already supports this, but we need a conversion from the existing `GetUint` method in viper.
The logger interface uses k,v pairs, but it was being called with a
format string, here.
Changed to use k,v pairs.
I didn't find any other instances of this problem.
Some codecs might have options that rely on Viper in the future
(eg. key delimiter) which requires initializing codecs
for each Viper instance.
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This interface is specific to decoding data into Viper's internal,
so it's okay to make it Viper specific.
BREAKING CHANGE: the decoder interface now accepts a map instead of an
interface
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
When merging a key where the target value is nil, the type of the target
and source do not match. What currently happens is an error is logged
and the key is skipped.
I have changed it so that it does the same thing as when the target key
is missing: copy the source value to the target.
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
* Added support for accessing slices
* Processed PR feedback
- renamed searchMapWithPathPrefixes to searchIndexableWithPathPrefixes
- moved source type specific search logic to speparate functions
- Inverted if statments to avoid the arrow pattern
* Quickly return from searchSliceWithPathPrefixes and searchMapWithPathPrefixes functions without intermediate variables
This change modifies BindEnv to permit a list of environment variable
names in order to support multiple env. vars. for the same config key.
When this form is used, env. keys take precedence in the written order.
Closes#971
* add parsing for stringToString flags
* add logic to return flags default if not val set, add a test
* extract parsing into single func
* add a few more cases
* return nil if unable to parse instead of panicing
* return map[string]interface in order to work with cast.ToStringMap
* mostly copy pflags implementation of the conversion to a stringtostring
* Add support to save file with no extension
The support introduced for files with no file extension is only partial as trying to save the config file would fail with `<file name> requires valid extension`
This adds support to saving such files
* Only consider files without extension if the config type is explicitly specified
* Hides unused variable in test
* First check for config type then for file without extension
Default value should be looked for by Get(), but not by IsSet().
This logic should remain inside find(), to make sure that shadowing
of keys is handled properly.
Fixes Issue #276.
If the config file does not exist and the force flag is not set,
OpenFile would not use O_CREATE flag, causing viper to fail with
error "File not exist" and to not create the config file.
This patch changes the behavior of writeConfig() so that if force is set
to false, OpenFile will use O_EXCL flag, thus failing if the file
already exists or creating a new file otherwise.
Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
Defering can cause trouble because we're writing to the file outside the function
where the defering is registered, calling f.Sync() ensures that bytes are flushed
to disk even is Close() is called too soon.
* Added a new `DecoderConfigOption` type allowing the user to write custom
functions that can override the default mapstructure.DecoderConfig
settings
* Added a new `DecodeHook` function which returns
a `DecoderConfigOption`. This allows the user to easily set their own
Decode hooks when Unmarshaling
* Updated Unmarshal, UnmarshalKey and defaultDecoderConfig to support variadic
trailing `DecoderConfigOption` functions to allow for customisation of
the default mapstructure.DecoderConfig
* Added a test case with example usage
Support override of symlink to config file
Include tests for WatchConfig of regular files, as well
as config file which links to a folder which is itself a
link to another folder in the same "watch dir" (the way
Kubernetes exposes config files from ConfigMaps mounted
on a volume in a Pod)
Also:
- Add synchronization with WaitGroup to ensure that the WatchConfig
is properly started before returning
- Remove the watcher when the Config file is removed.
Fixes#284
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>