chore: update Go modules to version 1.25.5, restructure models into pkg/models, and remove unused model files for improved organization and dependency management

This commit is contained in:
keven1024
2025-12-14 16:12:17 +08:00
parent 208875841e
commit 313ce4455f
29 changed files with 175 additions and 160 deletions

View File

@@ -1,13 +1,10 @@
module worker
go 1.24.0
toolchain go1.24.3
go 1.25.5
require (
dario.cat/mergo v1.0.2
github.com/hibiken/asynq v0.25.1
github.com/redis/go-redis/v9 v9.14.0
github.com/redis/go-redis/v9 v9.17.2
github.com/samber/lo v1.51.0
github.com/spf13/cast v1.10.0
github.com/spf13/viper v1.21.0

View File

@@ -1,5 +1,3 @@
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
@@ -30,8 +28,8 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.14.0 h1:u4tNCjXOyzfgeLN+vAZaW1xUooqWDqVEsZN0U01jfAE=
github.com/redis/go-redis/v9 v9.14.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI=
github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=

View File

@@ -1,60 +0,0 @@
package models
import (
"encoding/json"
"worker/internal/utils"
"dario.cat/mergo"
"github.com/redis/go-redis/v9"
)
type FileInfo struct {
FileSize int64 `json:"size"`
MimeType string `json:"mime_type"`
FileHash string `json:"hash"`
ChunkSize int64 `json:"chunk_size"`
}
type FileType string
const (
FileTypeInit FileType = "init"
FileTypeUpload FileType = "already"
)
type RedisFileInfo struct {
FileInfo
FileType FileType `json:"type"`
CreatedAt int64 `json:"created_at"`
Expire int64 `json:"expire"` // 只有上传文件(init)的时候有这个字段
}
func GetRedisFileInfo(fileId string) (*RedisFileInfo, error) {
rdb, ctx := utils.GetRedisClient()
fileInfoUnmarshalData, err := rdb.HGet(ctx, "015:fileInfoMap", fileId).Result()
if err == redis.Nil {
return nil, nil
}
if err != nil {
return nil, err
}
var fileInfoData RedisFileInfo
if err := json.Unmarshal([]byte(fileInfoUnmarshalData), &fileInfoData); err != nil {
return nil, err
}
return &fileInfoData, nil
}
func SetRedisFileInfo(fileId string, fileInfo RedisFileInfo) error {
rdb, ctx := utils.GetRedisClient()
old_fileInfo, err := GetRedisFileInfo(fileId)
if err != nil {
return err
}
if old_fileInfo != nil {
mergo.Merge(&fileInfo, old_fileInfo)
}
jsonData, _ := json.Marshal(fileInfo)
_, err = rdb.HSet(ctx, "015:fileInfoMap", fileId, string(jsonData)).Result()
return err
}

View File

@@ -1,31 +0,0 @@
package models
import (
"encoding/json"
"worker/internal/utils"
"github.com/redis/go-redis/v9"
)
func GetRedisFileShareRelational(fileId string) ([]string, error) {
rdb, ctx := utils.GetRedisClient()
fileShareRelationalUnmarshalData, err := rdb.HGet(ctx, "015:fileShareRelational", fileId).Result()
if err == redis.Nil {
return nil, nil
}
if err != nil {
return nil, err
}
var shareIDs []string
if err := json.Unmarshal([]byte(fileShareRelationalUnmarshalData), &shareIDs); err != nil {
return nil, err
}
return shareIDs, nil
}
func SetRedisFileShareRelational(fileId string, shareIDs []string) error {
rdb, ctx := utils.GetRedisClient()
jsonData, _ := json.Marshal(shareIDs)
_, err := rdb.HSet(ctx, "015:fileShareRelational", fileId, string(jsonData)).Result()
return err
}

View File

@@ -1,35 +0,0 @@
package models
import (
"encoding/json"
"fmt"
"time"
"worker/internal/utils"
"github.com/redis/go-redis/v9"
)
func GetRedisTaskInfo(taskId string) (*map[string]any, error) {
rdb, ctx := utils.GetRedisClient()
taskInfo := rdb.Get(ctx, fmt.Sprintf("015:taskInfoMap:%s", taskId))
taskInfoUnmarshalData, err := taskInfo.Result()
if err == redis.Nil {
return nil, nil
}
if err != nil {
return nil, err
}
var taskInfoData map[string]any
if err := json.Unmarshal([]byte(taskInfoUnmarshalData), &taskInfoData); err != nil {
return nil, err
}
return &taskInfoData, nil
}
func SetRedisTaskInfo(taskId string, taskInfo map[string]any) error {
rdb, ctx := utils.GetRedisClient()
jsonData, _ := json.Marshal(taskInfo)
_, err := rdb.Set(ctx, fmt.Sprintf("015:taskInfoMap:%s", taskId), jsonData, time.Hour).Result()
return err
}

View File

@@ -4,8 +4,8 @@ import (
"errors"
"os"
"path/filepath"
"pkg/models"
"time"
"worker/internal/models"
"worker/internal/utils"
)

View File

@@ -5,7 +5,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"worker/internal/models"
"pkg/models"
"worker/internal/utils"
"github.com/hibiken/asynq"

View File

@@ -7,7 +7,7 @@ import (
"fmt"
"os/exec"
"path/filepath"
"worker/internal/models"
"pkg/models"
"worker/internal/services"
"worker/internal/utils"

View File

@@ -5,7 +5,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"worker/internal/models"
"pkg/models"
"worker/internal/utils"
"github.com/hibiken/asynq"