Commit Graph

673 Commits

Author SHA1 Message Date
Andrew Stuart 2c12c60302
Fix nil pointer on watch function (#568) 2018-09-28 00:53:21 -07:00
Bjørn Erik Pedersen 3171ef9a22
Revert "Add go.sum to .gitignore"
This reverts commit 841bd4ebcd.
2018-09-07 15:06:02 +02:00
Bjørn Erik Pedersen 841bd4ebcd
Add go.sum to .gitignore
Seems that it's better practice to keep that in Git for "main modules".
2018-09-07 11:52:15 +02:00
Bjørn Erik Pedersen 8fb6420065
Add go.mod 2018-09-07 11:30:55 +02:00
Dr. Tobias Quathamer 0ac2068de9 Fix overflow error on 32 bit architectures (#340)
* Handle int64 separately for 32 bit architectures

* Remove tests which result in an overflow error on 32 bit architectures
2018-09-01 14:59:01 -06:00
Adhatama 8addaed22d Add README.md for Consul remote provider (#489) 2018-08-28 16:05:06 -06:00
Aarti Parikh 05116ad639 Revert "fix dep wrong case (#484)"
This reverts commit b7a62b2c00.
2018-08-28 02:34:36 -06:00
kun b7a62b2c00 fix dep wrong case (#484) 2018-08-28 01:37:55 -06:00
Robin Brämer e436d04e6d correct a comment on viper.Set() (#553)
correct regiser with register
2018-08-28 01:29:26 -06:00
Michael 40b1bbb9a8 travis: update go versions (#558) 2018-08-28 01:08:14 -06:00
Xavier Coulon 41f829b2c9 refactor test to avoid negative counter on WG
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
2018-08-06 09:29:13 +02:00
Xavier Coulon e12d3d32d1 Merge branch 'master' into Issue284_Kubernetes_config 2018-08-06 08:18:53 +02:00
Chris Reeves 907c19d40d Support customising mapstructure.DecoderConfig for Unmarshal
* 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
2018-08-03 14:57:45 +02:00
Xavier Coulon c1250e5dd7 apply review comments
use masks for checking the events.

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
2018-07-13 10:30:23 +02:00
Adriano d493c32b69 Update README.md (#470)
Fix typo in the environment variable usage documentation.
2018-07-10 13:30:20 +01:00
Brice Fernandes fb7a06477f
Add example of marshalling to string (#531) 2018-07-10 12:30:24 +01:00
Xavier Coulon 242f4890f5 Refactor with WaitGroup and check channel is open
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
2018-05-24 10:09:29 +02:00
Travis Jeffery 15738813a0 Add GetInt32 2018-05-07 09:10:07 +02:00
Michael Käufl 8dc2790b02 travis: update go versions 2018-04-04 20:33:25 +02:00
Bjørn Erik Pedersen b5e8006cbe
Undexport GetConfigFile
It was exported in previous commit, but we have GetConfigFileUsed -- so use that.
2018-03-19 19:50:19 +01:00
Bjørn Erik Pedersen 00ed41cdba
Export and fix GetConfigFile 2018-03-19 19:12:24 +01:00
Xavier Coulon e0f7631cf3 WatchConfig and Kubernetes (#284)
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>
2018-01-03 10:37:18 +01:00
Davor Kapsa aafc9e6bc7 travis: update go versions 2017-12-27 20:41:43 +01:00
Adam Sherwood 1a0c4a370c Feature/write config (#287)
* Added method to write into TOML file.

* Added functionality to export configuration based on config type. The feature supports JSON and TOML.

* Added method to write into YAML file.

* Fixed the issue of incorrect defer and error checking order. The error checking must be first otherwise it will cause panic.

* Add WriteConfig methods

* Add support for toml

* Add shared write function and safe methods

* Fix incorrectly modified imports

* Remove extra comments

* Fix spelling

* Make marshal spelling consistent throughout

* Add support for remaining configuration types

This commit moves a significant portion of the code back to viper.go to
facilitate having access to the object when reading the files. The purpose is to
add properties to the viper object at read time, so that we can add the comments
back to the file when writing.

* Add tests for each written file type

* Modify test for updated HCL specification

* Modify to only support HCL write in Go 1.7

* Revert "Modify to only support HCL write in Go 1.7"

This reverts commit 12b34bc4eb92cbf8ebfd56b79519f448607e3e51.

* Need to truncate the file before writing

* Write all settings including overrides

* Use filename variable

* Lint remote.go

* Fix toml return count error
2017-12-06 23:26:31 -05:00
Jeff Lindsay 4dddf7c62e Allow exists util function to take afero.Fs so it can be used with non-deafult instances of Viper (#405)
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
2017-11-09 21:57:16 +01:00
Kamil Wargula 8ef37cbca7 Fix incorrect name of function in README.md
Change `SetEnvReplacer` to `SetEnvKeyReplacer`
2017-10-20 12:40:09 +02:00
Bjørn Erik Pedersen d9cca5ef33 Go fmt viper.go 2017-09-29 23:06:42 +02:00
Alexander Krasnukhin 266e588e9e Add string slice support to defaultDecoderConfig
This way it correctly decodes string slices as well.
2017-09-29 21:44:38 +02:00
JG² 25b30aa063 Add Clairctl as a Go project that uses Viper
See #354
2017-07-22 23:52:07 -06:00
Nick Miyake 8ac2e2e20f Run gofmt on all existing code
Also:

* Add check to .travis.yml that verifies that all code is gofmt-compliant
* Touch up some newlines

See #351
2017-07-22 23:47:47 -06:00
Nick Miyake f257d19100 Fix a few minor typos/formatting issues with comments
See #350
2017-07-22 23:39:01 -06:00
Brad Peabody 04691bc570 Improve documentation for flags
See #329
2017-07-22 23:26:21 -06:00
Nikola Kovacs 9766537120 Fix grammar/typo in comment for getEnv()
See #310
2017-07-22 23:09:41 -06:00
Albert Nigmatzianov 16a9458573 Fix indentation in README.md
See #345
2017-07-22 22:54:24 -06:00
Anthony Fok df7314a14e Make minor copy-editing changes to README.md 2017-07-21 04:20:10 -06:00
Albert Nigmatzianov c1de95864d Prevent redundant type assertion in Get
There is no need to assert variables which already have appropriate
type.

name              old time/op    new time/op    delta
GetBool-4            554ns ± 3%     493ns ± 8%  -10.86%  (p=0.000 n=14+15)
Get-4                484ns ± 4%     414ns ± 7%  -14.37%  (p=0.000 n=14+15)
GetBoolFromMap-4    8.38ns ± 6%    7.83ns ± 7%   -6.59%  (p=0.000 n=15+15)

name              old alloc/op   new alloc/op   delta
GetBool-4            65.0B ± 0%     64.0B ± 0%   -1.54%  (p=0.000 n=15+15)
Get-4                64.0B ± 0%     64.0B ± 0%     ~     (all equal)
GetBoolFromMap-4     0.00B          0.00B          ~     (all equal)

name              old allocs/op  new allocs/op  delta
GetBool-4             5.00 ± 0%      4.00 ± 0%  -20.00%  (p=0.000 n=15+15)
Get-4                 5.00 ± 0%      4.00 ± 0%  -20.00%  (p=0.000 n=15+15)
GetBoolFromMap-4      0.00           0.00          ~     (all equal)
2017-06-19 14:43:13 +02:00
Nick Miyake a1ecfa6a20 Fix apostrophes in README
Fix "it's" -> "its".
2017-06-10 01:09:38 +02:00
Paweł Szczur 0967fc9ace Properly handle string slice values 2017-04-17 10:08:15 +02:00
Miguel Eduardo Gil Biraud 5d46e70da8 Fix UnmarshalKey handling of time.Duration
* Failing test for key unmarshaling with nested structs containing time.Duration

* Fix UnmarshalKey to use of defaultDecoderConfig
2017-04-10 11:26:50 +02:00
Wolfgang Friedl 84f94806c6 Avoid the start of go-routines which are never get stopped 2017-03-15 14:43:09 +01:00
Bjørn Erik Pedersen 0b5690fd87 Revert "remote: Avoid the start of go-routines which are never get stopped"
This reverts commit 11ca61e888.
2017-03-15 08:10:26 +01:00
Wolfgang Friedl 11ca61e888 remote: Avoid the start of go-routines which are never get stopped 2017-03-15 08:08:46 +01:00
Bjørn Erik Pedersen 7538d73b4e travis: Bump to Go 1.7.5 and 1.8 (Yay!) 2017-02-17 17:38:17 +01:00
Cameron Moore d90f2bb139 Only save config on success in ReadInConfig
If the user creates a invalid config file while watching for config
changes, the previous, valid config is not retained.  This commit only
overwrites the running config if unmarshalling was successful.
2017-02-17 17:31:47 +01:00
Kevin GEORGES 5ed0fc31f7 Fix MergeInConfig error return
UnsupportedConfigError was returned if config file not found

* Swap getConfigFile and getConfigType call
* Add a unit test
2016-12-13 10:38:49 +01:00
Albert Nigmatzianov 651d9d916a Document case-insensitivity for key taking methods 2016-10-29 23:33:52 +02:00
Bjørn Erik Pedersen 80ab6657f9 Copy and insensitivise maps in Set
Fixes #261
Closes #265
2016-10-24 21:20:41 +02:00
Benoît Masson 285f151019 Fixed AllKeys() to include env values added with BindEnv()
* Fixed: values bound with BindEnv added to AllKeys()

Cast was not working, and v.env wasn't used when merging keys.

Rewrote explicit and specific casts for maps storing strings or FlagValues.

* Added: test for BindEnv() and AllKeys()

To make sure AllSettings() and Unmarshal() will consider environment
variables added with BindEnv().
2016-10-23 23:04:21 +02:00
Benoît Masson 50515b700e Increase performance of nested keys search
* Fixed: insensitiviseMaps and tests

All keys (even nested ones) are now lower-cased recursively.

On the way, map[interface{}]interface{} are cast to map[string]interface{}

* Changed: simplified find() fast path and increase performance

Removed searchMapForKey(), fast path directly integrated into searchMap() and
searchMapWithPathPrefixes()
=> more generic (searchMapForKey() wasn't called everywhere it should have)

At the same time, significantly speed up searchMap() and searchMapWithPathPrefixes(),
which are still used for nested keys: the assumption that map keys are all
lower-cased allows to perform
    val = m[key]
instead of
    for k, v := range m {
      if strings.ToLower(k) == strings.ToLower(key) {
        val = v
      }
    }
=> i.e., directly access the map instead of enumerate the keys
2016-10-14 11:24:45 +02:00
Jonathan Anderson 44208030b3 Allow errors to propagate from getConfigFile(). (#161)
- propagate ConfigFileNotFoundError instead of using unsupported config type error when config file is not found
2016-10-13 13:33:30 +02:00