From 01ea6002c49e8bf97901c94a3f655eba9e783cd4 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Tue, 14 Nov 2023 14:57:41 -0800 Subject: [PATCH] replace go-humanize with format.HumanBytes --- cmd/cmd.go | 3 +-- format/bytes.go | 6 +++--- go.mod | 1 - go.sum | 2 -- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index d7839558..8fc6e4c4 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -20,7 +20,6 @@ import ( "syscall" "time" - "github.com/dustin/go-humanize" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "golang.org/x/crypto/ssh" @@ -173,7 +172,7 @@ func ListHandler(cmd *cobra.Command, args []string) error { for _, m := range models.Models { if len(args) == 0 || strings.HasPrefix(m.Name, args[0]) { - data = append(data, []string{m.Name, m.Digest[:12], humanize.Bytes(uint64(m.Size)), format.HumanTime(m.ModifiedAt, "Never")}) + data = append(data, []string{m.Name, m.Digest[:12], format.HumanBytes(m.Size), format.HumanTime(m.ModifiedAt, "Never")}) } } diff --git a/format/bytes.go b/format/bytes.go index ca5ac640..1cf5a762 100644 --- a/format/bytes.go +++ b/format/bytes.go @@ -12,11 +12,11 @@ const ( func HumanBytes(b int64) string { switch { case b > GigaByte: - return fmt.Sprintf("%d GB", b/GigaByte) + return fmt.Sprintf("%.1f GB", float64(b)/GigaByte) case b > MegaByte: - return fmt.Sprintf("%d MB", b/MegaByte) + return fmt.Sprintf("%.1f MB", float64(b)/MegaByte) case b > KiloByte: - return fmt.Sprintf("%d KB", b/KiloByte) + return fmt.Sprintf("%.1f KB", float64(b)/KiloByte) default: return fmt.Sprintf("%d B", b) } diff --git a/go.mod b/go.mod index b0f117bd..6d4c629a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/jmorganca/ollama go 1.20 require ( - github.com/dustin/go-humanize v1.0.1 github.com/emirpasic/gods v1.18.1 github.com/gin-gonic/gin v1.9.1 github.com/mattn/go-runewidth v0.0.14 diff --git a/go.sum b/go.sum index 0b94adbc..dab05d3d 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=