Files
bl/common/utils/file.go
昔念 e37d5a4d80 ```
refactor(config): 移除登录端口配置和相关功能

移除LoginPort配置项,注释掉相关代码逻辑

feat(admin): 添加版本查询接口

新增Version接口用于获取当前版本信息

refactor(login): 禁用注册服务

注释掉reg()函数调用,禁用登录相关的注册服务

refactor(deploy): 更新文件下载逻辑

修改自动化部署流程中的文件下载地址,使用新的配置域名

chore(utils): 添加最新逻辑文件获取工具

添加utils.GetLatestLogicFile方法用于获取最新的逻辑文件
```
2026-01-28 23:28:25 +08:00

60 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
)
// GetLatestLogicFile 遍历指定目录返回以logic_为前缀的最新修改文件路径
// dirPath: 目标目录路径(绝对路径或相对路径均可)
func GetLatestLogicFile(dirPath string) (string, error) {
// 1. 读取目录下所有文件/目录项
entries, err := os.ReadDir(dirPath)
if err != nil {
return "", fmt.Errorf("读取目录失败: %w", err)
}
var (
latestFile string // 记录最新文件的路径
latestModTime fs.FileInfo // 记录最新文件的文件信息(用于对比时间)
)
// 2. 遍历所有目录项,筛选并对比
for _, entry := range entries {
// 跳过目录,只处理普通文件
if entry.IsDir() {
continue
}
// 筛选以logic_开头的文件
filename := entry.Name()
if !strings.HasPrefix(filename, "logic_") {
continue
}
// 3. 获取文件的完整路径和详细信息(包含修改时间)
fileFullPath := filepath.Join(dirPath, filename)
fileInfo, err := os.Stat(fileFullPath)
if err != nil {
fmt.Printf("获取文件[%s]信息失败,跳过: %v\n", fileFullPath, err)
continue
}
// 4. 对比修改时间,更新最新文件记录
if latestModTime == nil || fileInfo.ModTime().After(latestModTime.ModTime()) {
latestFile = filename
latestModTime = fileInfo
}
}
// 5. 处理无符合条件文件的情况
if latestFile == "" {
return "", fmt.Errorf("目录[%s]下无符合条件的logic_前缀文件", dirPath)
}
return latestFile, nil
}