Browse Source

pkg/jsonmessage: JSONProgress.String(), JSONProgress.now(): simplify

- inline an intermediate variable
- remove a redundant intermediate function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 years ago
parent
commit
05cb0e5a7d
1 changed files with 4 additions and 7 deletions
  1. 4 7
      pkg/jsonmessage/jsonmessage.go

+ 4 - 7
pkg/jsonmessage/jsonmessage.go

@@ -56,8 +56,7 @@ func (p *JSONProgress) String() string {
 	if p.Total <= 0 {
 	if p.Total <= 0 {
 		switch p.Units {
 		switch p.Units {
 		case "":
 		case "":
-			current := units.HumanSize(float64(p.Current))
-			return fmt.Sprintf("%8v", current)
+			return fmt.Sprintf("%8v", units.HumanSize(float64(p.Current)))
 		default:
 		default:
 			return fmt.Sprintf("%d %s", p.Current, p.Units)
 			return fmt.Sprintf("%d %s", p.Current, p.Units)
 		}
 		}
@@ -112,12 +111,10 @@ func (p *JSONProgress) String() string {
 
 
 // shim for testing
 // shim for testing
 func (p *JSONProgress) now() time.Time {
 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
 // shim for testing