Skip to content

Commit

Permalink
refactor: use strconv instead of fmt
Browse files Browse the repository at this point in the history
closes dundee#100
  • Loading branch information
dundee committed Oct 25, 2021
1 parent f78bdce commit a1addc8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions pkg/analyze/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package analyze

import (
"encoding/json"
"fmt"
"io"
"strconv"
)

// EncodeJSON writes JSON representation of dir
Expand All @@ -24,7 +24,7 @@ func (f *Dir) EncodeJSON(writer io.Writer, topLevel bool) error {

if !f.GetMtime().IsZero() {
buff = append(buff, []byte(`,"mtime":`)...)
buff = append(buff, []byte(fmt.Sprint(f.GetMtime().Unix()))...)
buff = append(buff, []byte(strconv.FormatInt(f.GetMtime().Unix(), 10))...)
}

buff = append(buff, '}')
Expand Down Expand Up @@ -65,15 +65,15 @@ func (f *File) EncodeJSON(writer io.Writer, topLevel bool) error {
}
if f.GetSize() > 0 {
buff = append(buff, []byte(`,"asize":`)...)
buff = append(buff, []byte(fmt.Sprint(f.GetSize()))...)
buff = append(buff, []byte(strconv.FormatInt(f.GetSize(), 10))...)
}
if f.GetUsage() > 0 {
buff = append(buff, []byte(`,"dsize":`)...)
buff = append(buff, []byte(fmt.Sprint(f.GetUsage()))...)
buff = append(buff, []byte(strconv.FormatInt(f.GetUsage(), 10))...)
}
if !f.GetMtime().IsZero() {
buff = append(buff, []byte(`,"mtime":`)...)
buff = append(buff, []byte(fmt.Sprint(f.GetMtime().Unix()))...)
buff = append(buff, []byte(strconv.FormatInt(f.GetMtime().Unix(), 10))...)
}

if f.Flag == '@' {
Expand Down
3 changes: 2 additions & 1 deletion report/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"runtime/debug"
"sort"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -97,7 +98,7 @@ func (ui *UI) AnalyzePath(path string, _ *analyze.Dir) error {
buff.Write([]byte(`[1,2,{"progname":"gdu","progver":"`))
buff.Write([]byte(build.Version))
buff.Write([]byte(`","timestamp":`))
buff.Write([]byte(fmt.Sprint(time.Now().Unix())))
buff.Write([]byte(strconv.FormatInt(time.Now().Unix(), 10)))
buff.Write([]byte("},\n"))

if err = dir.EncodeJSON(&buff, true); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tui/show.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tui

import (
"fmt"
"strconv"
"strings"

"github.com/dundee/gdu/v5/build"
Expand Down Expand Up @@ -70,7 +70,7 @@ func (ui *UI) showDir() {
" Apparent size: " +
footerNumberColor +
ui.formatSize(totalSize, true, false) +
" Items: " + footerNumberColor + fmt.Sprint(itemCount) +
" Items: " + footerNumberColor + strconv.Itoa(itemCount) +
footerTextColor +
" Sorting by: " + ui.sortBy + " " + ui.sortOrder)

Expand Down

0 comments on commit a1addc8

Please sign in to comment.