From 2305836759536135c70e83584233f0a38e44e4a0 Mon Sep 17 00:00:00 2001 From: Parker DeWilde Date: Fri, 12 Apr 2024 15:06:36 -0700 Subject: [PATCH] Remove env lookup from CheckAppVersion() (#50) This was needed in an earlier version where I needed to parse http timeout from params to set context deadline appropriately. Now this deadline is inherited from ctx and not params, I can remove the parsing logic from the synchronous section. --- pkg/abcupdater/version.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pkg/abcupdater/version.go b/pkg/abcupdater/version.go index f6b2a47..8145560 100644 --- a/pkg/abcupdater/version.go +++ b/pkg/abcupdater/version.go @@ -100,30 +100,17 @@ To disable notifications for this new version, set {{.OptOutEnvVar}}="{{.Current // If no update is available: out() will not be called. // If there is an error: out() will not be called, message will be logged as WARN. // If the context is canceled: out() is not called. -// If processing config fails: an error will be returned synchronously. // Example out(): `func(s string) {fmt.Fprintln(os.Stderr, s)}`. -func CheckAppVersion(ctx context.Context, params *CheckVersionParams, out func(string)) (func(), error) { +func CheckAppVersion(ctx context.Context, params *CheckVersionParams, out func(string)) func() { cancel := func() {} if _, ok := ctx.Deadline(); !ok { ctx, cancel = context.WithTimeout(ctx, time.Second*2) } - lookuper := params.Lookuper - if lookuper == nil { - lookuper = envconfig.OsLookuper() - } - var c config - if err := envconfig.ProcessWith(ctx, &envconfig.Config{ - Target: &c, - Lookuper: lookuper, - }); err != nil { - cancel() - return nil, fmt.Errorf("failed to process envconfig: %w", err) - } return asyncFunctionCall(ctx, func() (string, error) { defer cancel() return CheckAppVersionSync(ctx, params) - }, out), nil + }, out) } // CheckAppVersionSync checks if a newer version of an app is available. Any relevant update info will be