refactor: extract path logic to path.go and run go fmt on codebase

This commit is contained in:
duorameng
2026-05-22 14:52:51 +08:00
parent b6fd889661
commit 4c283a60d5
55 changed files with 409 additions and 420 deletions
+2 -2
View File
@@ -486,7 +486,7 @@ func (es *ExecutorService) ExecuteDispatcher(ctx context.Context, req *executor.
// 组合指令逻辑已移至 executor.ExecuteWithHooks 中,此处不再处理
// 以避免指令被重复组合。
// 远程任务
if task.AgentID != nil && *task.AgentID != "" {
// 将请求中已包含的环境变量(已合并)传递给 Agent
@@ -806,7 +806,7 @@ func (es *ExecutorService) StopTaskExecution(logID string) error {
taskLog.Status = constant.TaskStatusFailed
errorMessage := "任务执行实例已丢失(可能由于系统重启导致),已自动同步状态为失败"
taskLog.Error = models.BigText(errorMessage)
// 更新数据库状态
database.DB.Model(&taskLog).Updates(map[string]interface{}{
"status": taskLog.Status,
+1 -1
View File
@@ -4,11 +4,11 @@ import (
"encoding/json"
"time"
"github.com/engigu/baihu-panel/internal/constant"
"github.com/engigu/baihu-panel/internal/database"
"github.com/engigu/baihu-panel/internal/logger"
"github.com/engigu/baihu-panel/internal/models"
"github.com/engigu/baihu-panel/internal/systime"
"github.com/engigu/baihu-panel/internal/constant"
"github.com/engigu/baihu-panel/internal/utils"
)
+3 -4
View File
@@ -92,7 +92,6 @@ func (ts *TaskService) CreateTask(p *TaskParam) *models.Task {
}
database.DB.Select("*").Create(task)
return task
}
@@ -111,7 +110,7 @@ func (ts *TaskService) GetTasksWithPagination(page, pageSize int, name string, a
if name != "" {
query = query.Where("name LIKE ? OR remark LIKE ?", "%"+name+"%", "%"+name+"%")
}
// 标签筛选 (并集)
if tags != "" {
tagList := strings.Split(tags, ",")
@@ -200,7 +199,7 @@ func (ts *TaskService) UpdateTask(id string, p *TaskParam) *models.Task {
func (ts *TaskService) DeleteTask(id string) bool {
// 同时删除关联的通知推送设置
database.DB.Where("type = ? AND data_id = ?", constant.BindingTypeTask, id).Delete(&models.NotifyBinding{})
result := database.DB.Where("id = ?", id).Delete(&models.Task{})
return result.RowsAffected > 0
}
@@ -208,7 +207,7 @@ func (ts *TaskService) DeleteTask(id string) bool {
func (ts *TaskService) BatchDeleteTasks(ids []string) int64 {
// 同时删除关联的通知推送设置
database.DB.Where("type = ? AND data_id IN ?", constant.BindingTypeTask, ids).Delete(&models.NotifyBinding{})
result := database.DB.Where("id IN ?", ids).Delete(&models.Task{})
return result.RowsAffected
}
+1 -1
View File
@@ -64,7 +64,7 @@ type TinyLog struct {
path string
writer *bufio.Writer
subscribers []chan []byte
remainder []byte // Leftover bytes from previous write (partial lines)
remainder []byte // Leftover bytes from previous write (partial lines)
masks []string // Secrets to mask
closed bool
}
+3 -3
View File
@@ -23,7 +23,7 @@ func TestTinyLog_UTF8Splitting(t *testing.T) {
}
_, _ = tl.Write(part2)
// Currently it should collect both parts but still no newline,
// Currently it should collect both parts but still no newline,
// so remainder should be 5 bytes.
if len(tl.remainder) != 5 {
t.Errorf("Expected remainder len 5, got %d", len(tl.remainder))
@@ -58,7 +58,7 @@ func TestTinyLog_CarriageReturn(t *testing.T) {
if err != nil {
t.Fatalf("ReadLastLines failed: %v", err)
}
// Should contain both progress lines (or at least be split correctly)
if !bytes.Contains(data, []byte("progress: 50%")) {
t.Errorf("Expected output to contain 'progress: 50%%', got %q", data)
@@ -94,7 +94,7 @@ func TestTinyLog_LongLineCut(t *testing.T) {
// Our logic finds the last safe boundary before maxLogBufferLen.
// RuneStart(E4) at maxLogBufferLen-1 is true. FullRune(E4 at maxLogBufferLen-1 in payload[:maxLogBufferLen]) is false.
// So lastSafe should be maxLogBufferLen-1.
// The first maxLogBufferLen-1 bytes (all 'A') should be processed.
// The "你" should be in remainder.