update: file size humanize show

This commit is contained in:
2024-09-06 17:57:11 +08:00
parent 292bbeab89
commit e7686d9a96

View File

@@ -6,9 +6,6 @@ package file
import (
"os"
"path/filepath"
"strings"
"github.com/dustin/go-humanize"
)
type FileInfo struct {
@@ -17,7 +14,7 @@ type FileInfo struct {
LinkCount int64 `json:"linkCount"` // 硬链接数目
Owner string `json:"owner"` // 所属用户
Group string `json:"group"` // 所属组
Size string `json:"size"` // 文件的大小
Size int64 `json:"size"` // 文件的大小
ModifiedTime int64 `json:"modifiedTime"` // 最后修改时间,单位为秒
FileName string `json:"fileName"` // 文件的名称
}
@@ -43,14 +40,13 @@ func GetFileInfo(dir, suffix string) ([]FileInfo, error) {
// check if match suffix
if (suffix != "" && filepath.Ext(path) == suffix) || suffix == "" {
humanReadableSize := humanize.Bytes(uint64(info.Size()))
fileInfo := FileInfo{
FileType: fileType,
FileMode: info.Mode().String(),
LinkCount: 0,
Owner: "-",
Group: "-",
Size: strings.ToUpper(humanReadableSize),
Size: info.Size(),
ModifiedTime: info.ModTime().Unix(),
FileName: info.Name(),
}