chore(deps): 更新项目依赖并添加文件路径获取功能
- 添加 .arts 到 .gitignore 文件 - 新增 GetResourceAllPath 函数用于获取资源文件路径列表 - 升级 gin 框架从 v1.7.7 到 v1.12.0 - 添加 gf-common 依赖库 - 更新多个间接依赖包版本包括 go-playground、mysql 驱动等 - 添加 byteDance sonic 等性能优化库 - 移除旧的验证器相关依赖
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.magicany.cc/black1552/gin-base/log"
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
func FileExists(path string) bool {
|
||||
@@ -11,3 +17,38 @@ func FileExists(path string) bool {
|
||||
func EmptyFile(path string) bool {
|
||||
return gfile.IsEmpty(path)
|
||||
}
|
||||
|
||||
func GetResourceAllPath(path string) []string {
|
||||
if path == "" {
|
||||
path = "/"
|
||||
}
|
||||
basePath, _ := os.Getwd()
|
||||
filePath := filepath.Join(basePath, "resource")
|
||||
if path != "/" {
|
||||
filePath += filepath.Join(filePath, path)
|
||||
}
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Error("open file error", err)
|
||||
panic(err)
|
||||
}
|
||||
paths, err := f.Readdirnames(-1)
|
||||
_ = f.Close()
|
||||
if err != nil {
|
||||
log.Error("read file error", err)
|
||||
panic(err)
|
||||
}
|
||||
pathArr := garray.NewStrArray()
|
||||
for _, v := range paths {
|
||||
if gstr.Contains(v, ".") {
|
||||
if path != "/" {
|
||||
pathArr.Append("/static/" + path + "/" + v)
|
||||
} else {
|
||||
pathArr.Append("/static/" + v)
|
||||
}
|
||||
} else {
|
||||
pathArr.Append(v)
|
||||
}
|
||||
}
|
||||
return pathArr.Slice()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user