From af5844a885cc9a459734ce84f8399eb4334c6ebf Mon Sep 17 00:00:00 2001 From: bogcon Date: Fri, 5 Aug 2022 16:14:48 +0300 Subject: [PATCH] * upgrades --- Makefile | 2 +- assert_test.go | 16 ++++------------ config.go | 20 +++++++++---------- config_mock.go | 34 +++++++++++++++++---------------- go.mod | 12 ++++++------ go.sum | 30 ++++++++++++++--------------- loader_consul.go | 18 ++++++++++++----- loader_decorator_alter_value.go | 2 -- loader_decorator_filter_kv.go | 28 ++++++++++++++------------- loader_decorator_flatten.go | 13 +++++++------ loader_ini.go | 12 ++++++------ loader_plain.go | 1 - scripts/consul_data_provider.sh | 2 +- scripts/setup_dockers_deb.sh | 10 ++++++---- 14 files changed, 102 insertions(+), 98 deletions(-) diff --git a/Makefile b/Makefile index bbb149b..75102f4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -LINTER_VERSION=v1.46.2 +LINTER_VERSION=v1.48.0 LINTER=./bin/golangci-lint ifeq ($(OS),Windows_NT) LINTER=./bin/golangci-lint.exe diff --git a/assert_test.go b/assert_test.go index c9d9321..d64f6da 100644 --- a/assert_test.go +++ b/assert_test.go @@ -17,19 +17,11 @@ import ( func assertEqual(t *testing.T, expected interface{}, actual interface{}) bool { t.Helper() if !reflect.DeepEqual(expected, actual) { - expectedType, actualType := "nil", "nil" - expectedT, actualT := reflect.TypeOf(expected), reflect.TypeOf(actual) - if expectedT != nil { - expectedType = expectedT.String() - } - if actualT != nil { - actualType = actualT.String() - } t.Errorf( - "\n\t"+`expected "%+v" (%s),`+ - "\n\t"+`but got "%+v" (%s)`+"\n", - expected, expectedType, - actual, actualType, + "\n\t"+`expected "%+v" (%T),`+ + "\n\t"+`but got "%+v" (%T)`+"\n", + expected, expected, + actual, actual, ) return false diff --git a/config.go b/config.go index 12d96b8..75c55fe 100644 --- a/config.go +++ b/config.go @@ -305,9 +305,9 @@ type DefaultConfigOption func(*DefaultConfig) // By default, configuration reload is disabled. // // Usage example: -// // enable config reload at an interval of 5 minutes: -// cfg, err := xconf.NewDefaultConfig(loader, xconf.DefaultConfigWithReloadInterval(5 * time.Minute)) // +// // enable config reload at an interval of 5 minutes: +// cfg, err := xconf.NewDefaultConfig(loader, xconf.DefaultConfigWithReloadInterval(5 * time.Minute)) func DefaultConfigWithReloadInterval(reloadInterval time.Duration) DefaultConfigOption { return func(config *DefaultConfig) { config.reloadInterval = reloadInterval @@ -320,15 +320,15 @@ func DefaultConfigWithReloadInterval(reloadInterval time.Duration) DefaultConfig // will return Foo's value. // // Usage example: -// cfg, err := xconf.NewDefaultConfig(loader, xconf.DefaultConfigWithIgnoreCaseSensitivity()) -// if err != nil { -// panic(err) -// } -// value1 := cfg.Get("foo") -// value2 := cfg.Get("FOO") -// value3 := cfg.Get("foO") -// // all values are equal // +// cfg, err := xconf.NewDefaultConfig(loader, xconf.DefaultConfigWithIgnoreCaseSensitivity()) +// if err != nil { +// panic(err) +// } +// value1 := cfg.Get("foo") +// value2 := cfg.Get("FOO") +// value3 := cfg.Get("foO") +// // all values are equal func DefaultConfigWithIgnoreCaseSensitivity() DefaultConfigOption { return func(config *DefaultConfig) { config.ignoreCaseSensitivity = true diff --git a/config_mock.go b/config_mock.go index 83e1eab..c2f5a14 100644 --- a/config_mock.go +++ b/config_mock.go @@ -21,12 +21,13 @@ type MockConfig struct { // NewMockConfig instantiates new mocked Config with given key-values configuration. // Make sure you pass an even number of elements and that the keys are strings. +// // Usage example: -// mock := xconf.NewMockConfig( -// "foo", "bar", -// "year", 2022, -// ) // +// mock := xconf.NewMockConfig( +// "foo", "bar", +// "year", 2022, +// ) func NewMockConfig(kv ...interface{}) *MockConfig { mock := &MockConfig{ configMap: make(map[string]interface{}), @@ -71,20 +72,21 @@ func (mock *MockConfig) SetKeyValues(kv ...interface{}) { // SetGetCallback sets the given callback to be executed inside Get() method. // You can inject yourself to make assertions upon passed parameter(s) this way. +// // Usage example: -// mock.SetGetCallback(func(key string, def ...interface{}) { -// switch mock.GetCallsCount() { -// case 1: -// if key != "expectedKeyAtCall1" { -// t.Error("...") -// } -// case 2: -// if key != "expectedKeyAtCall2" { -// t.Error("...") -// } -// } -// }) // +// mock.SetGetCallback(func(key string, def ...interface{}) { +// switch mock.GetCallsCount() { +// case 1: +// if key != "expectedKeyAtCall1" { +// t.Error("...") +// } +// case 2: +// if key != "expectedKeyAtCall2" { +// t.Error("...") +// } +// } +// }) func (mock *MockConfig) SetGetCallback(callback func(key string, def ...interface{})) { mock.getCallback = callback } diff --git a/go.mod b/go.mod index 99558b4..1f31cc1 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/actforgood/xconf go 1.16 require ( - github.com/actforgood/xerr v1.0.0-rc.4 - github.com/actforgood/xlog v1.0.0-rc.3 + github.com/actforgood/xerr v1.0.0 + github.com/actforgood/xlog v1.0.0 github.com/joho/godotenv v1.4.0 github.com/magiconair/properties v1.8.6 github.com/spf13/cast v1.5.0 @@ -13,10 +13,10 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.21.0 // indirect - golang.org/x/net v0.0.0-20220622184535-263ec571b305 // indirect - golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664 // indirect - google.golang.org/genproto v0.0.0-20220623142657-077d458a5694 // indirect - google.golang.org/grpc v1.47.0 + golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 // indirect + google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612 // indirect + google.golang.org/grpc v1.48.0 + google.golang.org/protobuf v1.28.1 // indirect gopkg.in/ini.v1 v1.66.6 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 310a20f..c458986 100644 --- a/go.sum +++ b/go.sum @@ -6,11 +6,10 @@ github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3 github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= -github.com/actforgood/xerr v1.0.0-rc.3/go.mod h1:rPtRaXUESl0b69ZzQ+2GTx9f+idPEfkahTZ67fNfbSQ= -github.com/actforgood/xerr v1.0.0-rc.4 h1:C/TkKn7N//r6N52aL/t4o7U0QVpq1w5kHugdI/KPbt0= -github.com/actforgood/xerr v1.0.0-rc.4/go.mod h1:rPtRaXUESl0b69ZzQ+2GTx9f+idPEfkahTZ67fNfbSQ= -github.com/actforgood/xlog v1.0.0-rc.3 h1:Qk4el6/ZhDJe0TU1ZQHLr7qMiR4uEqph1dWN2vtia2k= -github.com/actforgood/xlog v1.0.0-rc.3/go.mod h1:CMeFlK96pr2V3eeH2Xe7QfpkRpdD1XMwVCSCjGf1sAQ= +github.com/actforgood/xerr v1.0.0 h1:I4BuVj360o8ZeusZWmA4gXrxiVVoIiYLAHhBKzBTVQk= +github.com/actforgood/xerr v1.0.0/go.mod h1:rPtRaXUESl0b69ZzQ+2GTx9f+idPEfkahTZ67fNfbSQ= +github.com/actforgood/xlog v1.0.0 h1:swQeBTvuKQ2ps3BnbsBnzsWxovfpmrDvHv0bV37xfMs= +github.com/actforgood/xlog v1.0.0/go.mod h1:F00w/eb7/o2cSehlLK1fEzcieSPqmBnllE6TgURVtzc= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -327,8 +326,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220622184535-263ec571b305 h1:dAgbJ2SP4jD6XYfMNLVj0BF21jo2PjChrtGaAvF5M3I= -golang.org/x/net v0.0.0-20220622184535-263ec571b305/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 h1:N9Vc/rorQUDes6B9CNdIxAn5jODGj2wzfrei2x4wNj4= +golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -369,9 +368,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664 h1:wEZYwx+kK+KlZ0hpvP2Ls1Xr4+RWnlzGFwPP0aiDjIU= -golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 h1:9vYwv7OjYaky/tlAeD7C4oC9EsPTlaFl1H2jS++V+ME= +golang.org/x/sys v0.0.0-20220804214406-8e32c043e418/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -408,8 +407,8 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20220623142657-077d458a5694 h1:itnFmgk4Ls5nT+mYO2ZK6F0DpKsGZLhB5BB9y5ZL2HA= -google.golang.org/genproto v0.0.0-20220623142657-077d458a5694/go.mod h1:KEWEmljWE5zPzLBa/oHl6DaEt9LmfH6WtH1OHIvleBA= +google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612 h1:NX3L5YesD5qgxxrPHdKqHH38Ao0AG6poRXG+JljPsGU= +google.golang.org/genproto v0.0.0-20220804142021-4e6b2dfa6612/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= @@ -417,8 +416,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8= -google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= +google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -431,8 +430,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/loader_consul.go b/loader_consul.go index 5eb460f..fb478bb 100644 --- a/loader_consul.go +++ b/loader_consul.go @@ -286,8 +286,10 @@ func ConsulLoaderWithHTTPClient(client *http.Client) ConsulLoaderOption { // By default, is set to "http://127.0.0.1:8500". // Consul host can also be set through CONSUL_HTTP_ADDR and CONSUL_HTTP_SSL // ENV as in official hashicorp's client. +// // Example: -// xconf.ConsulLoaderWithHost("http://consul.example.com:8500") +// +// xconf.ConsulLoaderWithHost("http://consul.example.com:8500") func ConsulLoaderWithHost(host string) ConsulLoaderOption { return func(loader *ConsulLoader) { loader.reqInfo.baseURL = host @@ -305,8 +307,10 @@ func ConsulLoaderWithContext(ctx context.Context) ConsulLoaderOption { // ConsulLoaderWithQueryDataCenter specifies the datacenter to query. // This will default to the datacenter of the agent being queried. // See also official doc https://www.consul.io/api-docs/kv#read-key . +// // Example: -// xconf.ConsulLoaderWithQueryDataCenter("my-dc") +// +// xconf.ConsulLoaderWithQueryDataCenter("my-dc") func ConsulLoaderWithQueryDataCenter(dc string) ConsulLoaderOption { return func(loader *ConsulLoader) { loader.reqInfo.setQuery(consulQueryParamDataCenter, dc) @@ -319,8 +323,10 @@ func ConsulLoaderWithQueryDataCenter(dc string) ConsulLoaderOption { // may be specified as '*' and then results will be returned for all namespaces. // Added in Consul 1.7.0. // See also official doc https://www.consul.io/api-docs/kv#read-key . +// // Example: -// xconf.ConsulLoaderWithQueryNamespace("my-ns") +// +// xconf.ConsulLoaderWithQueryNamespace("my-ns") func ConsulLoaderWithQueryNamespace(ns string) ConsulLoaderOption { return func(loader *ConsulLoader) { loader.reqInfo.setQuery(consulQueryParamNamespace, ns) @@ -337,10 +343,12 @@ func ConsulLoaderWithPrefix() ConsulLoaderOption { // ConsulLoaderWithRequestHeader adds a request header. // You can set the auth token for example: -// xconf.ConsulLoaderWithRequestHeader(xconf.ConsulHeaderAuthToken, "someSecretToken") +// +// xconf.ConsulLoaderWithRequestHeader(xconf.ConsulHeaderAuthToken, "someSecretToken") +// // or some basic auth header: -// xconf.ConsulLoaderWithRequestHeader("Authorization", "Basic " + base64.StdEncoding.EncodeToString([]byte(usr + ":" + pwd)) // +// xconf.ConsulLoaderWithRequestHeader("Authorization", "Basic " + base64.StdEncoding.EncodeToString([]byte(usr + ":" + pwd)) func ConsulLoaderWithRequestHeader(hName, hValue string) ConsulLoaderOption { return func(loader *ConsulLoader) { loader.reqInfo.headers[hName] = hValue diff --git a/loader_decorator_alter_value.go b/loader_decorator_alter_value.go index e6e709e..b26cb47 100644 --- a/loader_decorator_alter_value.go +++ b/loader_decorator_alter_value.go @@ -39,7 +39,6 @@ func AlterValueLoader(loader Loader, transformation AlterValueFunc, keys ...stri // If the original value is not a string, the value remains unaltered. // // Example: "bread,eggs,milk" => ["bread", "eggs", "milk"]. -// func ToStringList(sep string) AlterValueFunc { return func(value interface{}) interface{} { if strValue, ok := value.(string); ok { @@ -56,7 +55,6 @@ func ToStringList(sep string) AlterValueFunc { // If the original value is not a string, the value remains unaltered. // // Example: "10,100,1000" => [10, 100, 1000]. -// func ToIntList(sep string) AlterValueFunc { return func(value interface{}) interface{} { if strValue, ok := value.(string); ok { diff --git a/loader_decorator_filter_kv.go b/loader_decorator_filter_kv.go index 17f30dd..92c60c4 100644 --- a/loader_decorator_filter_kv.go +++ b/loader_decorator_filter_kv.go @@ -32,11 +32,12 @@ type FilterKV interface { // with the appropriate signature, FilterKVWhitelistFunc(fn) is a // FilterKV that calls fn of type FilterTypeWhitelist. // fn should return true if the KV is whitelisted. +// // Example: -// xconf.FilterKVWhitelistFunc(func(key string, _ interface{}) bool { -// return key == "KEEP_ME_1" || key == "KEEP_ME_2" -// }) // +// xconf.FilterKVWhitelistFunc(func(key string, _ interface{}) bool { +// return key == "KEEP_ME_1" || key == "KEEP_ME_2" +// }) type FilterKVWhitelistFunc func(key string, value interface{}) bool // IsAllowed returns true if a key-value is whitelisted. @@ -54,11 +55,12 @@ func (filter FilterKVWhitelistFunc) Type() FilterType { // with the appropriate signature, FilterKVBlacklistFunc(fn) is a // FilterKV that calls fn and has type FilterTypeBlacklist. // fn should return true if the KV is blacklisted. +// // Example: -// xconf.FilterKVBlacklistFunc(func(key string, _ interface{}) bool { -// return key == "DENY_ME_1" || key == "DENY_ME_2" -// }) // +// xconf.FilterKVBlacklistFunc(func(key string, _ interface{}) bool { +// return key == "DENY_ME_1" || key == "DENY_ME_2" +// }) type FilterKVBlacklistFunc func(key string, value interface{}) bool // IsAllowed returns false if a key-value is blacklisted. @@ -136,9 +138,9 @@ func FilterKVLoader(loader Loader, filters ...FilterKV) Loader { // FilterKeyWithPrefix returns true if a key has given prefix. // It can be used as a FilterKV like: -// xconf.FilterKVWhitelistFunc(xconf.FilterKeyWithPrefix(prefix)) -// xconf.FilterKVBlacklistFunc(xconf.FilterKeyWithPrefix(prefix)) // +// xconf.FilterKVWhitelistFunc(xconf.FilterKeyWithPrefix(prefix)) +// xconf.FilterKVBlacklistFunc(xconf.FilterKeyWithPrefix(prefix)) func FilterKeyWithPrefix(prefix string) func(key string, _ interface{}) bool { return func(key string, _ interface{}) bool { return strings.HasPrefix(key, prefix) @@ -147,9 +149,9 @@ func FilterKeyWithPrefix(prefix string) func(key string, _ interface{}) bool { // FilterKeyWithSuffix returns true if a key has given suffix. // It can be used as a FilterKV like: -// xconf.FilterKVWhitelistFunc(xconf.FilterKeyWithSuffix(suffix)) -// xconf.FilterKVBlacklistFunc(xconf.FilterKeyWithSuffix(suffix)) // +// xconf.FilterKVWhitelistFunc(xconf.FilterKeyWithSuffix(suffix)) +// xconf.FilterKVBlacklistFunc(xconf.FilterKeyWithSuffix(suffix)) func FilterKeyWithSuffix(suffix string) func(key string, _ interface{}) bool { return func(key string, _ interface{}) bool { return strings.HasSuffix(key, suffix) @@ -158,9 +160,9 @@ func FilterKeyWithSuffix(suffix string) func(key string, _ interface{}) bool { // FilterExactKeys returns true if a key is present in the provided list. // It can be used as a FilterKV like: -// xconf.FilterKVWhitelistFunc(xconf.FilterExactKeys(key1, key2)) -// xconf.FilterKVBlacklistFunc(xconf.FilterExactKeys(key1, key2)) // +// xconf.FilterKVWhitelistFunc(xconf.FilterExactKeys(key1, key2)) +// xconf.FilterKVBlacklistFunc(xconf.FilterExactKeys(key1, key2)) func FilterExactKeys(keys ...string) func(key string, _ interface{}) bool { return func(key string, _ interface{}) bool { for _, k := range keys { @@ -175,8 +177,8 @@ func FilterExactKeys(keys ...string) func(key string, _ interface{}) bool { // FilterEmptyValue returns true if a value is nil or "". // It can be used as a FilterKV like: -// xconf.FilterKVBlacklistFunc(xconf.FilterEmptyValue) // +// xconf.FilterKVBlacklistFunc(xconf.FilterEmptyValue) func FilterEmptyValue(_ string, value interface{}) bool { if value == nil { return true diff --git a/loader_decorator_flatten.go b/loader_decorator_flatten.go index 2ef0f0c..4f807c4 100644 --- a/loader_decorator_flatten.go +++ b/loader_decorator_flatten.go @@ -9,14 +9,15 @@ import "github.com/spf13/cast" // FlattenLoader decorates another loader to add shortcuts to leaves' information // in a nested configuration key. +// // Example, given the configuration: // -// { -// "mysql": { -// "host": "127.0.0.1", -// "port": 3306 -// } -// } +// { +// "mysql": { +// "host": "127.0.0.1", +// "port": 3306 +// } +// } // // 2 additional flat keys will be added to above standard configuration: "mysql.host", "mysql.port" // for easy access of leaf-keys. diff --git a/loader_ini.go b/loader_ini.go index d51b389..c862a48 100644 --- a/loader_ini.go +++ b/loader_ini.go @@ -78,10 +78,10 @@ func IniFileLoaderWithLoadOptions(iniLoadOpts ini.LoadOptions) IniFileLoaderOpti // for a different section from default is used. // // You may want for example to provide a custom function that ignores the section: -// xconf.IniFileLoaderWithSectionKeyFunc(func(_, key string) string { -// return key -// }) // +// xconf.IniFileLoaderWithSectionKeyFunc(func(_, key string) string { +// return key +// }) func IniFileLoaderWithSectionKeyFunc(keyFunc func(section, key string) string) IniFileLoaderOption { return func(loader *IniFileLoader) { loader.keyFunc = keyFunc @@ -92,9 +92,9 @@ func IniFileLoaderWithSectionKeyFunc(keyFunc func(section, key string) string) I // in the final configuration key-value map for an ini key under a section. // Example: given the ini content: // -// foo=bar -// [time] -// year=2022 +// foo=bar +// [time] +// year=2022 // // it will produce "foo" and "time/year" for the 2 above keys. var defaultIniKeyFunc = func(section, key string) string { diff --git a/loader_plain.go b/loader_plain.go index 79993ad..0d2fcfb 100644 --- a/loader_plain.go +++ b/loader_plain.go @@ -18,7 +18,6 @@ package xconf // any other configuration...) // // - to provide any application hardcoded configs. -// func PlainLoader(configMap map[string]interface{}) Loader { // make a copy to preserve state at current time. // (prevents user modification of configMap from outside while using the loader). diff --git a/scripts/consul_data_provider.sh b/scripts/consul_data_provider.sh index 9c7c4a2..b0172dc 100755 --- a/scripts/consul_data_provider.sh +++ b/scripts/consul_data_provider.sh @@ -4,7 +4,7 @@ # This script provides the data used in integration tests for Consul. # # Example of running a local Consul instance (https://hub.docker.com/_/consul): -# docker run -d --name=integration-consul -p 8500:8500 -e CONSUL_BIND_INTERFACE=eth0 consul:1.12.2 +# docker run -d --name=integration-consul -p 8500:8500 -e CONSUL_BIND_INTERFACE=eth0 consul:1.12.3 # # Example of usage of this script: # ./path/to/scripts/consul_data_provider.sh diff --git a/scripts/setup_dockers_deb.sh b/scripts/setup_dockers_deb.sh index 566cb09..7f77d41 100755 --- a/scripts/setup_dockers_deb.sh +++ b/scripts/setup_dockers_deb.sh @@ -39,21 +39,23 @@ network=$(docker inspect --format '{{json .NetworkSettings.Networks}}' `hostname echo "network = ${network}" echo ">>> Run Consul Docker Image" -docker pull -q consul:1.12.2 +DOCKER_CONSUL_IMAGE_VER=consul:1.12.3 +docker pull -q $DOCKER_CONSUL_IMAGE_VER docker run -d \ --name=integration-consul \ -p 8500:8500 \ --network "${network}" \ -e CONSUL_BIND_INTERFACE=eth0 \ - consul:1.12.2 + $DOCKER_CONSUL_IMAGE_VER echo ">>> Run Etcd Docker Image" -docker pull -q quay.io/coreos/etcd:v3.5.4 +DOCKER_ETCD_IMAGE_VER=quay.io/coreos/etcd:v3.5.4 +docker pull -q $DOCKER_ETCD_IMAGE_VER docker run -d \ --name=integration-etcd \ -p 2379:2379 \ --network "${network}" \ - quay.io/coreos/etcd:v3.5.4 \ + $DOCKER_ETCD_IMAGE_VER \ /usr/local/bin/etcd -advertise-client-urls http://integration-etcd:2379 -listen-client-urls http://0.0.0.0:2379 echo ">>> Show Running Docker Containers"