27 lines
558 B
Go
27 lines
558 B
Go
package service
|
|
|
|
import (
|
|
"blog/internal/model/vo"
|
|
"blog/third_party/database"
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type fileService struct {
|
|
}
|
|
|
|
var FileService fileService
|
|
|
|
func (*fileService) GetFile(relId string) []byte {
|
|
ctx := context.Background()
|
|
key := "blog:file:" + relId
|
|
bytes, err := database.RedisTemplate.Get(ctx, key).Bytes()
|
|
if err != nil {
|
|
var file vo.CommonFiles
|
|
database.GormTemplate.Table("common_files").Where("id = ?", relId).First(&file)
|
|
bytes = file.Data
|
|
database.RedisTemplate.Set(ctx, key, bytes, time.Duration(0))
|
|
}
|
|
return bytes
|
|
}
|