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