Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/provider/appconfig/aws…
Browse files Browse the repository at this point in the history
…-sdk-go-f3fb70cb69
  • Loading branch information
ktong authored Aug 26, 2024
2 parents e0e9683 + f6fe82a commit 9a2abf5
Show file tree
Hide file tree
Showing 46 changed files with 55 additions and 118 deletions.
7 changes: 5 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ linters-settings:
Use of this source code is governed by a MIT license found in the LICENSE file.
goimports:
local-prefixes: github.com/nil-go/konf
gosec:
excludes:
# Flags for potentially-unsafe casting of ints, similar problem to globally-disabled G103
- G115
govet:
enable:
- shadow
Expand Down Expand Up @@ -41,7 +45,7 @@ linters:
- canonicalheader
- containedctx
- contextcheck
# copyloopvar // go 1.22
- copyloopvar
- cyclop
- decorder
# depguard
Expand All @@ -54,7 +58,6 @@ linters:
- errchkjson
- errname
- errorlint
- exportloopref
- exhaustive
# exhaustruct
- fatcontext
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Removed

- Remove support for Golang 1.21 (#457).

## [1.2.2] - 2024-07-08

### Fixed
Expand Down
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ becoming coupled to a particular configuration source.
- [konf.OnChange](#usage) for registering callbacks while configuration changes.
- [konf.Explain](#understand-the-configuration) for understanding where the configuration is loaded from.
- [Various providers](#configuration-providers) for loading configuration from major clouds,
[AWS](examples/aws), [Azure](examples/azure), and [GCP](examples/gcp) with [Notifier](notifier) for notifying the changes of configuration.
[AWS](examples/aws), [Azure](examples/azure), and [GCP](examples/gcp) with [Notifier](notifier) for notifying the
changes of configuration.
- [Zero dependencies](go.mod) in core module which supports loading configuration
from environment variables,flags, and embed file system.

Expand Down Expand Up @@ -112,6 +113,7 @@ while the configuration source(s) is managed "up stack" (e.g. in or near `main()
Application developers can then switch configuration sources(s) as necessary.

## Change Notification

The providers for loading configuration from clouds periodically poll the configuration source.
It also supports watching the changes of configuration using corresponding notifier.
For example, the `sns` notifier notifies the changes of `appconfig` and `s3` provider:
Expand Down Expand Up @@ -150,22 +152,24 @@ to monitor the status of configuration loading/watching, e.g. recording metrics.

There are providers for the following configuration sources.

| Loader | Load From | Watch Changes | Notifier |
|:------------------------------------------|:----------------------------------------------------------------------------------------|:-------------:|:--------------------------|
| [`env`](provider/env) | environment variables | | |
| [`fs`](provider/fs) | [fs.FS](https://pkg.go.dev/io/fs) | | |
| [`file`](provider/file) | file || |
| [`flag`](provider/flag) | [flag](https://pkg.go.dev/flag) | | |
| [`pflag`](provider/pflag) | [spf13/pflag](https://github.com/spf13/pflag) | | |
| [`appconfig`](provider/appconfig) | [AWS AppConfig](https://aws.amazon.com/systems-manager/features/appconfig/) || [sns](notifier/sns) |
| [`s3`](provider/s3) | [AWS S3](https://aws.amazon.com/s3) || [sns](notifier/sns) |
| [`parameterstore`](provider/parameterstore) | [AWS ParameterStore](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) || [sns](notifier/sns) |
| [`azappconfig`](provider/azappconfig) | [Azure App Configuration](https://azure.microsoft.com/en-us/products/app-configuration) || [azservicebus](notifier/azservicebus) |
| [`azblob`](provider/azblob) | [Azure Blob Storage](https://azure.microsoft.com/en-us/products/storage/blobs) || [azservicebus](notifier/azservicebus) |
| [`secretmanager`](provider/secretmanager) | [GCP Secret Manager](https://cloud.google.com/security/products/secret-manager) || [pubsub](notifier/pubsub) |
| [`gcs`](provider/gcs) | [GCP Cloud Storage](https://cloud.google.com/storage) || [pubsub](notifier/pubsub) |

[cobra](https://github.com/spf13/cobra) is supported through the [`pflag`](provider/pflag) loader, with the [`pflag.WithFlagSet`](https://pkg.go.dev/github.com/nil-go/konf/provider/pflag#WithFlagSet) option:
| Loader | Load From | Watch Changes | Notifier |
|:--------------------------------------------|:------------------------------------------------------------------------------------------------------------------------|:-------------:|:--------------------------------------|
| [`env`](provider/env) | environment variables | | |
| [`fs`](provider/fs) | [fs.FS](https://pkg.go.dev/io/fs) | | |
| [`file`](provider/file) | file || |
| [`flag`](provider/flag) | [flag](https://pkg.go.dev/flag) | | |
| [`pflag`](provider/pflag) | [spf13/pflag](https://github.com/spf13/pflag) | | |
| [`appconfig`](provider/appconfig) | [AWS AppConfig](https://aws.amazon.com/systems-manager/features/appconfig/) || [sns](notifier/sns) |
| [`s3`](provider/s3) | [AWS S3](https://aws.amazon.com/s3) || [sns](notifier/sns) |
| [`parameterstore`](provider/parameterstore) | [AWS ParameterStore](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) || [sns](notifier/sns) |
| [`azappconfig`](provider/azappconfig) | [Azure App Configuration](https://azure.microsoft.com/en-us/products/app-configuration) || [azservicebus](notifier/azservicebus) |
| [`azblob`](provider/azblob) | [Azure Blob Storage](https://azure.microsoft.com/en-us/products/storage/blobs) || [azservicebus](notifier/azservicebus) |
| [`secretmanager`](provider/secretmanager) | [GCP Secret Manager](https://cloud.google.com/security/products/secret-manager) || [pubsub](notifier/pubsub) |
| [`gcs`](provider/gcs) | [GCP Cloud Storage](https://cloud.google.com/storage) || [pubsub](notifier/pubsub) |

[cobra](https://github.com/spf13/cobra) is supported through the [`pflag`](provider/pflag) loader, with the [
`pflag.WithFlagSet`](https://pkg.go.dev/github.com/nil-go/konf/provider/pflag#WithFlagSet) option:

```go
config.Load(kflag.New(&config, kflag.WithFlagSet(yourCobraCmd.Flags())))
```
Expand Down
2 changes: 1 addition & 1 deletion benchmark/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/benchmark

go 1.21
go 1.22

require (
github.com/knadh/koanf/providers/env v0.1.0
Expand Down
6 changes: 0 additions & 6 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func TestConfig_Load(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -260,8 +258,6 @@ func TestConfig_Unmarshal(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -355,8 +351,6 @@ Here are other value(loader)s:
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/nil-go/konf

go 1.21
go 1.22

retract v0.6.1 // It does not work while file is not exist
2 changes: 0 additions & 2 deletions internal/convert/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,6 @@ func TestConverter(t *testing.T) { //nolint:maintidx
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions internal/convert/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func withHookFunc[F, T any](hookFunc func(F, T) error) Option {
}

options.hooks = append(options.hooks, hook{
fromType: reflect.TypeOf((*F)(nil)).Elem(),
toType: reflect.TypeOf((*T)(nil)).Elem(),
fromType: reflect.TypeFor[F](),
toType: reflect.TypeFor[T](),
hook: func(f, t any) error {
from, ok := f.(F)
if !ok {
Expand Down
2 changes: 0 additions & 2 deletions internal/maps/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func TestInsert(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions internal/maps/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ func TestMerge(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
9 changes: 4 additions & 5 deletions internal/maps/sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ func TestSub(t *testing.T) {
},
}

for _, tc := range testcases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
for _, testcase := range testcases {
t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

actual := maps.Sub(tc.values, tc.path, ".")
assert.Equal(t, tc.expected, actual)
actual := maps.Sub(testcase.values, testcase.path, ".")
assert.Equal(t, testcase.expected, actual)
})
}
}
9 changes: 4 additions & 5 deletions internal/maps/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ func TestTransformKeys(t *testing.T) {
},
}

for _, tc := range testcases {
tc := tc
t.Run(tc.description, func(t *testing.T) {
for _, testcase := range testcases {
t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

maps.TransformKeys(tc.src, tc.keyMap, tc.mapKeyCaseSensitive)
assert.Equal(t, tc.expected, tc.src)
maps.TransformKeys(testcase.src, testcase.keyMap, testcase.mapKeyCaseSensitive)
assert.Equal(t, testcase.expected, testcase.src)
})
}
}
2 changes: 1 addition & 1 deletion internal/nocopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ func (c *NoCopy[T]) Check() {
}

if c.addr != c {
panic("illegal use of non-zero " + reflect.TypeOf((*T)(nil)).Elem().Name() + " copied by value")
panic("illegal use of non-zero " + reflect.TypeFor[T]().Name() + " copied by value")
}
}
2 changes: 1 addition & 1 deletion notifier/azservicebus/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/notifier/azservicebus

go 1.21
go 1.22

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0
Expand Down
2 changes: 1 addition & 1 deletion notifier/pubsub/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/notifier/pubsub

go 1.21
go 1.22

require (
cloud.google.com/go/compute/metadata v0.5.0
Expand Down
1 change: 0 additions & 1 deletion notifier/pubsub/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ level=WARN msg="Fail to delete pubsub subscription." topic=topic subscription=pr
}

for _, testcase := range testcases {
testcase := testcase
t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion notifier/sns/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/notifier/sns

go 1.21
go 1.22

require (
github.com/aws/aws-sdk-go-v2 v1.30.4
Expand Down
1 change: 0 additions & 1 deletion notifier/sns/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ level=WARN msg="Fail to delete sqs message." queue=https://sqs.us-west-2.amazona
}

for _, testcase := range testcases {
testcase := testcase
t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 0 additions & 4 deletions provider/appconfig/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ func TestAppConfig_Load(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -676,8 +674,6 @@ func TestAppConfig_Watch(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion provider/appconfig/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/provider/appconfig

go 1.21
go 1.22

require (
github.com/aws/aws-sdk-go-v2 v1.30.4
Expand Down
4 changes: 0 additions & 4 deletions provider/azappconfig/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func TestAppConfig_Load(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -216,8 +214,6 @@ list settings error
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion provider/azappconfig/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/provider/azappconfig

go 1.21
go 1.22

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0
Expand Down
2 changes: 0 additions & 2 deletions provider/azappconfig/internal/maps/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ func TestInsert(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 0 additions & 4 deletions provider/azblob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func TestBlob_Load(t *testing.T) {
t.Parallel()

for _, testcase := range testcases() {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -77,8 +75,6 @@ func TestBlob_Watch(t *testing.T) {
t.Parallel()

for _, testcase := range append(testcases(), watchcases()...) {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion provider/azblob/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/provider/azblob

go 1.21
go 1.22

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0
Expand Down
4 changes: 0 additions & 4 deletions provider/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func TestEnv_Load(t *testing.T) {
t.Setenv("P.N", "")

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
values, err := env.New(testcase.opts...).Load()
assert.NoError(t, err)
Expand Down Expand Up @@ -105,8 +103,6 @@ func TestEnv_String(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions provider/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ func TestFile_Load(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion provider/file/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nil-go/konf/provider/file

go 1.21
go 1.22

require github.com/fsnotify/fsnotify v1.7.0

Expand Down
2 changes: 0 additions & 2 deletions provider/file/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestFile_Watch(t *testing.T) {
}

for _, testcase := range testcases {
testcase := testcase

t.Run(testcase.description, func(t *testing.T) {
tmpFile := path.Join(t.TempDir(), "watch.json")
assert.NoError(t, os.WriteFile(tmpFile, []byte(`{"p": {"k": "v"}}`), 0o600))
Expand Down
Loading

0 comments on commit 9a2abf5

Please sign in to comment.