Quellcode durchsuchen

replace go-humanize with format.HumanBytes

Michael Yang vor 1 Jahr
Ursprung
Commit
01ea6002c4
4 geänderte Dateien mit 4 neuen und 8 gelöschten Zeilen
  1. 1 2
      cmd/cmd.go
  2. 3 3
      format/bytes.go
  3. 0 1
      go.mod
  4. 0 2
      go.sum

+ 1 - 2
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")})
 		}
 	}
 

+ 3 - 3
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)
 	}

+ 0 - 1
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

+ 0 - 2
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=