diff --git a/.golangci.yml b/.golangci.yml index f7f80eef..2a6ee813 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -43,7 +43,7 @@ linters: - contextcheck - cyclop - decorder - - depguard + # depguard - dogsled - dupl - durationcheck @@ -81,6 +81,7 @@ linters: - goprintffuncname - gosec - gosimple + - gosmopolitan - govet - grouper - importas @@ -91,6 +92,7 @@ linters: - loggercheck - maintidx - makezero + - mirror - misspell - musttag - nakedret @@ -112,6 +114,7 @@ linters: - sqlclosecheck - staticcheck - stylecheck + - tagalign - tagliatelle - tenv - testableexamples @@ -128,6 +131,7 @@ linters: - whitespace - wrapcheck # wsl + - zerologlint issues: exclude-rules: diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b5b4aa4..6feb987b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v0.2.0] - 3/18/2023 ### Removed + - Remove file.WithLog to favor standard log.Printf (#32). ## [v0.1.0] - 3/12/2023 diff --git a/README.md b/README.md index b5f0daa1..834f84e8 100644 --- a/README.md +++ b/README.md @@ -108,4 +108,3 @@ compatibility with these versions in the following manner: testing for the oldest (now archived upstream) version of Go. This, and future, releases of konf may include features only supported by the currently supported versions of Go. - diff --git a/global.go b/global.go index 18cc29d3..36faf18b 100644 --- a/global.go +++ b/global.go @@ -64,7 +64,7 @@ func Watch(ctx context.Context, fns ...func()) error { } // SetGlobal makes c the global Config. After this call, -// the konf package's functions (e.g. konf.Get) will read from config. +// the konf package's functions (e.g. konf.Get) will read from the global config. // // The default global config only loads configuration from environment variables. func SetGlobal(config *Config) { diff --git a/internal/maps/merge.go b/internal/maps/merge.go index e4de2823..3556df23 100644 --- a/internal/maps/merge.go +++ b/internal/maps/merge.go @@ -14,9 +14,9 @@ func Merge(dst, src map[string]any) { // Ensure key is lower case since the path is case-insensitive. key = strings.ToLower(key) - // Add the srcVal if the key does not exist in the dst map. - dstVal, exist := dst[key] - if !exist { + // Direct override if the dstVal is not map[string]any. + dstMap, succeed := dst[key].(map[string]any) + if !succeed { dst[key] = srcVal continue @@ -30,14 +30,6 @@ func Merge(dst, src map[string]any) { continue } - // Direct override if the dstVal is not map[string]any. - dstMap, succeed := dstVal.(map[string]any) - if !succeed { - dst[key] = srcVal - - continue - } - // Merge if the srcVal and dstVal are both map[string]any. Merge(dstMap, srcMap) } diff --git a/provider.go b/provider.go index e07df064..b2ae034d 100644 --- a/provider.go +++ b/provider.go @@ -9,8 +9,7 @@ import "context" // // Load loads configuration and returns as a nested map[string]any. // It requires that the string keys should be nested like `{parent: {child: {key: 1}}}`. -// The key in returned map should be case-insensitive, -// otherwise random overridden exists. +// The key in returned map should be case-insensitive, otherwise random overridden exists. type Loader interface { Load() (map[string]any, error) } @@ -26,10 +25,8 @@ type Watcher interface { // ConfigAware is the interface that wraps the WithConfig method. // -// WithConfig enables provider loads configuration from providers -// before it in Load and Watch methods. -// -// It ensures the WithConfig is called before Load and Watch. +// WithConfig enables provider loads configuration from providers before it. +// It ensures the WithConfig is called before executing methods in Loader and Watcher. type ConfigAware interface { WithConfig(*Config) } diff --git a/provider/pflag/pflag.go b/provider/pflag/pflag.go index 5ac1e8c2..bb1b614f 100644 --- a/provider/pflag/pflag.go +++ b/provider/pflag/pflag.go @@ -47,19 +47,21 @@ func New(opts ...Option) PFlag { func (f PFlag) Load() (map[string]any, error) { values := make(map[string]any) - f.set.VisitAll(func(flag *pflag.Flag) { - if f.prefix != "" && !strings.HasPrefix(flag.Name, f.prefix) { - return - } + f.set.VisitAll( + func(flag *pflag.Flag) { + if f.prefix != "" && !strings.HasPrefix(flag.Name, f.prefix) { + return + } - val := f.flagVal(flag) - // Skip zero default value to avoid overriding values set by other loader. - if !flag.Changed && reflect.ValueOf(val).IsZero() { - return - } + val := f.flagVal(flag) + // Skip zero default value to avoid overriding values set by other loader. + if !flag.Changed && reflect.ValueOf(val).IsZero() { + return + } - maps.Insert(values, strings.Split(flag.Name, f.delimiter), val) - }) + maps.Insert(values, strings.Split(flag.Name, f.delimiter), val) + }, + ) return values, nil }