This commit is contained in:
wangchuxiao
2022-03-23 15:44:34 +08:00
parent 8034ddc413
commit e6c36411cb
7 changed files with 93 additions and 6 deletions
+15 -1
View File
@@ -1,6 +1,11 @@
package utils
import "os"
import (
"fmt"
"math/rand"
"os"
"time"
)
// Determine whether the given path is a folder
func IsDir(path string) bool {
@@ -20,3 +25,12 @@ func IsFile(path string) bool {
func MkDir(path string) error {
return os.MkdirAll(path, os.ModePerm)
}
func GetNewFileNameAndContentType(fileType string) (string, string) {
newName := fmt.Sprintf("%d-%d%s", time.Now().UnixNano(), rand.Int(), fileType)
contentType := ""
if fileType == "img" {
contentType = "image/" + fileType[1:]
}
return newName, contentType
}