Skip to content

Commit

Permalink
* upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
bogcon committed Aug 5, 2022
1 parent 4389315 commit af5844a
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 4 additions & 12 deletions assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 18 additions & 16 deletions config_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
30 changes: 15 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -408,17 +407,17 @@ 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=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
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=
Expand All @@ -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=
Expand Down
18 changes: 13 additions & 5 deletions loader_consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions loader_decorator_alter_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
28 changes: 15 additions & 13 deletions loader_decorator_filter_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions loader_decorator_flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit af5844a

Please sign in to comment.