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>
This commit is contained in:
Sebastiaan van Stijn 2023-04-30 23:37:09 +02:00
parent 4cadee65b3
commit 05cb0e5a7d
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -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