修复可能的 context 泄露以及遗漏的错误处理 (#1965)

* 修复结构体 tag 字段的错误使用
This commit is contained in:
Feng.YJ 2024-12-17 16:59:06 +08:00 committed by GitHub
parent f6c2ce45c1
commit 2bf423b42f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 10 deletions

9
.gitignore vendored
View File

@ -1,4 +1,3 @@
.idea/
/web/node_modules /web/node_modules
/web/dist /web/dist
@ -33,3 +32,11 @@ server/uploads/
*.iml *.iml
web/.pnpm-debug.log web/.pnpm-debug.log
web/pnpm-lock.yaml web/pnpm-lock.yaml
# binary files
*.exe
# SQLite database files
*.db
*.sqlite
*.sqlite3

View File

@ -8,10 +8,10 @@ import (
// Info 公告 结构体 // Info 公告 结构体
type Info struct { type Info struct {
global.GVA_MODEL global.GVA_MODEL
Title string `json:"title" form:"title" gorm:"column:title;comment:公告标题;"` //标题 Title string `json:"title" form:"title" gorm:"column:title;comment:公告标题;"` //标题
Content string `json:"content" form:"content" gorm:"column:content;comment:公告内容;type:text;"` //内容 Content string `json:"content" form:"content" gorm:"column:content;comment:公告内容;type:text;"` //内容
UserID *int `json:"userID" form:"userID" gorm:"column:user_id;comment:发布者;"` //作者 UserID *int `json:"userID" form:"userID" gorm:"column:user_id;comment:发布者;"` //作者
Attachments datatypes.JSON `json:"attachments" form:"attachments" gorm:"column:attachments;comment:相关附件;"swaggertype:"array,object"` //附件 Attachments datatypes.JSON `json:"attachments" form:"attachments" gorm:"column:attachments;comment:相关附件;" swaggertype:"array,object"` //附件
} }
// TableName 公告 Info自定义表名 gva_announcements_info // TableName 公告 Info自定义表名 gva_announcements_info

View File

@ -87,12 +87,12 @@ func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath stri
"v1": newPath, "v1": newPath,
"v2": newMethod, "v2": newMethod,
}).Error }).Error
e := casbinService.Casbin()
err = e.LoadPolicy()
if err != nil { if err != nil {
return err return err
} }
return err
e := casbinService.Casbin()
return e.LoadPolicy()
} }
//@author: [piexlmax](https://github.com/piexlmax) //@author: [piexlmax](https://github.com/piexlmax)

View File

@ -67,7 +67,6 @@ func (m *Minio) UploadFile(file *multipart.FileHeader) (filePathres, key string,
} }
f.Close() // 创建文件 defer 关闭 f.Close() // 创建文件 defer 关闭
// 对文件名进行加密存储 // 对文件名进行加密存储
ext := filepath.Ext(file.Filename) ext := filepath.Ext(file.Filename)
filename := utils.MD5V([]byte(strings.TrimSuffix(file.Filename, ext))) + ext filename := utils.MD5V([]byte(strings.TrimSuffix(file.Filename, ext))) + ext
@ -91,8 +90,10 @@ func (m *Minio) UploadFile(file *multipart.FileHeader) (filePathres, key string,
} }
func (m *Minio) DeleteFile(key string) error { func (m *Minio) DeleteFile(key string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
// Delete the object from MinIO // Delete the object from MinIO
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
err := m.Client.RemoveObject(ctx, m.bucket, key, minio.RemoveObjectOptions{}) err := m.Client.RemoveObject(ctx, m.bucket, key, minio.RemoveObjectOptions{})
return err return err
} }