From a26673f1d59146b1ce4c18497951f6a059016a86 Mon Sep 17 00:00:00 2001 From: ktong Date: Sat, 10 Feb 2024 15:30:12 -0800 Subject: [PATCH] refactor --- provider/appconfig/appconfig.go | 14 ++++++-------- provider/flag/option.go | 2 +- provider/pflag/option.go | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/provider/appconfig/appconfig.go b/provider/appconfig/appconfig.go index 3ae86ded..b65745d2 100644 --- a/provider/appconfig/appconfig.go +++ b/provider/appconfig/appconfig.go @@ -107,7 +107,7 @@ func (a *AppConfig) Watch(ctx context.Context, onChange func(map[string]any)) er for { select { case <-ticker.C: - out, err := a.load(ctx) + values, err := a.load(ctx) if err != nil { a.logger.WarnContext( ctx, "Error when reloading from AWS AppConfig", @@ -120,8 +120,8 @@ func (a *AppConfig) Watch(ctx context.Context, onChange func(map[string]any)) er continue } - if out != nil { - onChange(out) + if values != nil { + onChange(values) } case <-ctx.Done(): return nil @@ -208,6 +208,8 @@ func (c *clientProxy) loadClient(ctx context.Context) (*appconfigdata.Client, er c.clientOnce.Do(func() { if reflect.ValueOf(c.config).IsZero() { if c.config, err = config.LoadDefaultConfig(ctx); err != nil { + err = fmt.Errorf("load default AWS config: %w", err) + return } } @@ -215,9 +217,5 @@ func (c *clientProxy) loadClient(ctx context.Context) (*appconfigdata.Client, er c.client = appconfigdata.NewFromConfig(c.config) }) - if err != nil { - return nil, fmt.Errorf("load client: %w", err) - } - - return c.client, nil + return c.client, err } diff --git a/provider/flag/option.go b/provider/flag/option.go index 2514c452..b58d1797 100644 --- a/provider/flag/option.go +++ b/provider/flag/option.go @@ -42,7 +42,7 @@ func WithDelimiter(delimiter string) Option { } } -// WithNameSplitter provides the function used to split environment variable names into nested keys. +// WithNameSplitter provides the function used to split flag names into nested keys. // If it returns an nil/[]string{}/[]string{""}, the variable will be ignored. // // For example, with the default splitter, an flag name like "parent.child.key" diff --git a/provider/pflag/option.go b/provider/pflag/option.go index 3ad4a9b2..ac0362f6 100644 --- a/provider/pflag/option.go +++ b/provider/pflag/option.go @@ -43,7 +43,7 @@ func WithDelimiter(delimiter string) Option { } } -// WithNameSplitter provides the function used to split environment variable names into nested keys. +// WithNameSplitter provides the function used to split flag names into nested keys. // If it returns an nil/[]string{}/[]string{""}, the variable will be ignored. // // For example, with the default splitter, an flag name like "parent.child.key"