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

65
pkg/models/file.go Normal file
View File

@@ -0,0 +1,65 @@
package models
import (
"encoding/json"
"pkg/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
}
func GetRedisFileInfoAll() (map[string]string, error) {
rdb, ctx := utils.GetRedisClient()
return rdb.HGetAll(ctx, "015:fileInfoMap").Result()
}

View File

@@ -0,0 +1,31 @@
package models
import (
"encoding/json"
"pkg/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
}

13
pkg/models/go.mod Normal file
View File

@@ -0,0 +1,13 @@
module pkg/models
go 1.25.5
require (
dario.cat/mergo v1.0.2
github.com/redis/go-redis/v9 v9.17.2
)
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
)

7
pkg/models/go.sum Normal file
View File

@@ -0,0 +1,7 @@
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/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI=

28
pkg/models/pickupcode.go Normal file
View File

@@ -0,0 +1,28 @@
package models
import (
"fmt"
"time"
"pkg/utils"
"github.com/redis/go-redis/v9"
)
func GetRedisPickupData(pickupCode string) (string, error) {
rdb, ctx := utils.GetRedisClient()
ShareId, err := rdb.Get(ctx, fmt.Sprintf("015:pickupCode:%s", pickupCode)).Result()
if err == redis.Nil {
return "", nil
}
if err != nil {
return "", err
}
return ShareId, nil
}
func SetRedisPickupData(pickupCode string, shareId string) (bool, error) {
rdb, ctx := utils.GetRedisClient()
ok, err := rdb.SetNX(ctx, fmt.Sprintf("015:pickupCode:%s", pickupCode), shareId, time.Until(time.Now().Add(24*time.Hour))).Result()
return ok, err
}

67
pkg/models/share.go Normal file
View File

@@ -0,0 +1,67 @@
package models
import (
"encoding/json"
"fmt"
"time"
"pkg/utils"
"dario.cat/mergo"
"github.com/redis/go-redis/v9"
)
type RedisShareInfo struct {
// Id string `json:"id"`
CreatedAt int64 `json:"created_at"`
Owner string `json:"owner"`
Type ShareType `json:"type"`
Data string `json:"data"` // 分享数据 文件分享为文件id 文本分享为文本内容
ExpireAt int64 `json:"expire_time"`
ViewNum int64 `json:"download_nums"`
Password string `json:"password"`
NotifyEmail []string `json:"notify_email"`
FileName string `json:"file_name"`
// PickupCode bool `json:"pickup_code"`
}
type ShareType string
const (
ShareTypeFile ShareType = "file"
ShareTypeText ShareType = "text"
)
func GetRedisShareInfo(shareId string) (*RedisShareInfo, error) {
rdb, ctx := utils.GetRedisClient()
shareInfo := rdb.Get(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId))
shareInfoUnmarshalData, err := shareInfo.Result()
ttl, _ := rdb.TTL(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId)).Result()
if err == redis.Nil {
return nil, nil
}
if err != nil {
return nil, err
}
var shareInfoData RedisShareInfo
if err := json.Unmarshal([]byte(shareInfoUnmarshalData), &shareInfoData); err != nil {
return nil, err
}
shareInfoData.ExpireAt = time.Now().Add(ttl).Unix()
return &shareInfoData, nil
}
func SetRedisShareInfo(shareId string, shareInfo RedisShareInfo) error {
rdb, ctx := utils.GetRedisClient()
old_shareInfo, err := GetRedisShareInfo(shareId)
if err != nil {
return err
}
if old_shareInfo != nil {
mergo.Merge(&shareInfo, old_shareInfo)
}
jsonData, _ := json.Marshal(shareInfo)
_, err = rdb.Set(ctx, fmt.Sprintf("015:shareInfoMap:%s", shareId), string(jsonData), time.Until(time.Unix(shareInfo.ExpireAt, 0))).Result()
return err
}

53
pkg/models/stat.go Normal file
View File

@@ -0,0 +1,53 @@
package models
import (
"encoding/json"
"pkg/utils"
"dario.cat/mergo"
"github.com/redis/go-redis/v9"
)
// 统计数据结构
type StatData struct {
FileSize int64 `json:"file_size"` // 文件大小
FileNum int64 `json:"file_num"` // 文件数量
ShareNum int64 `json:"share_num"` // 分享数量
DownloadNum int64 `json:"download_num"` // 下载数量
}
func GetRedisStat(key string) (*StatData, error) {
rdb, ctx := utils.GetRedisClient()
statUnmarshalData, err := rdb.HGet(ctx, "015:stat", key).Result()
if err == redis.Nil {
return nil, nil
}
if err != nil {
return nil, err
}
var stat StatData
if err := json.Unmarshal([]byte(statUnmarshalData), &stat); err != nil {
return nil, err
}
return &stat, nil
}
func SetRedisStat(key string, stat StatData) error {
rdb, ctx := utils.GetRedisClient()
old_stat, err := GetRedisStat(key)
if err != nil {
return err
}
if old_stat != nil {
mergo.Merge(&stat, old_stat)
}
jsonData, _ := json.Marshal(stat)
_, err = rdb.HSet(ctx, "015:stat", key, string(jsonData)).Result()
return err
}
func GetRedisStatAll() (map[string]string, error) {
rdb, ctx := utils.GetRedisClient()
return rdb.HGetAll(ctx, "015:stat").Result()
}

36
pkg/models/task.go Normal file
View File

@@ -0,0 +1,36 @@
package models
import (
"encoding/json"
"fmt"
"time"
"pkg/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
}

32
pkg/utils/go.mod Normal file
View File

@@ -0,0 +1,32 @@
module pkg/utils
go 1.23.0
toolchain go1.24.11
require (
github.com/hibiken/asynq v0.25.1
github.com/redis/go-redis/v9 v9.17.2
github.com/spf13/viper v1.21.0
)
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
)

56
pkg/utils/go.sum Normal file
View File

@@ -0,0 +1,56 @@
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hibiken/asynq v0.25.1 h1:phj028N0nm15n8O2ims+IvJ2gz4k2auvermngh9JhTw=
github.com/hibiken/asynq v0.25.1/go.mod h1:pazWNOLBu0FEynQRBvHA26qdIKRSmfdIfUm4HdsLmXg=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
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/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=
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=