From 05cb0e5a7dd5ec0eb035530913fbe4f12da40ebf Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Apr 2023 23:37:09 +0200 Subject: [PATCH] pkg/jsonmessage: JSONProgress.String(), JSONProgress.now(): simplify - inline an intermediate variable - remove a redundant intermediate function Signed-off-by: Sebastiaan van Stijn --- pkg/jsonmessage/jsonmessage.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/jsonmessage/jsonmessage.go b/pkg/jsonmessage/jsonmessage.go index 764a8090aa..2def699d38 100644 --- a/pkg/jsonmessage/jsonmessage.go +++ b/pkg/jsonmessage/jsonmessage.go @@ -56,8 +56,7 @@ func (p *JSONProgress) String() string { if p.Total <= 0 { switch p.Units { case "": - current := units.HumanSize(float64(p.Current)) - return fmt.Sprintf("%8v", current) + return fmt.Sprintf("%8v", units.HumanSize(float64(p.Current))) default: return fmt.Sprintf("%d %s", p.Current, p.Units) } @@ -112,12 +111,10 @@ func (p *JSONProgress) String() string { // shim for testing func (p *JSONProgress) now() time.Time { - if p.nowFunc == nil { - p.nowFunc = func() time.Time { - return time.Now().UTC() - } + if p.nowFunc != nil { + return p.nowFunc() } - return p.nowFunc() + return time.Now().UTC() } // shim for testing