1Panel/backend/utils/files/utils.go

37 lines
592 B
Go
Raw Normal View History

2022-08-24 11:10:50 +08:00
package files
import (
2022-08-30 17:59:59 +08:00
"github.com/gabriel-vasile/mimetype"
2022-08-24 11:10:50 +08:00
"os"
"os/user"
"strconv"
)
func IsSymlink(mode os.FileMode) bool {
return mode&os.ModeSymlink != 0
}
func GetUsername(uid uint32) string {
usr, err := user.LookupId(strconv.Itoa(int(uid)))
if err != nil {
return ""
}
return usr.Username
}
func GetGroup(gid uint32) string {
usr, err := user.LookupGroupId(strconv.Itoa(int(gid)))
if err != nil {
return ""
}
return usr.Name
}
2022-08-30 17:59:59 +08:00
func GetMimeType(path string) string {
mime, err := mimetype.DetectFile(path)
if err != nil {
return ""
}
return mime.String()
}