修复可能的 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/dist
@ -33,3 +32,11 @@ server/uploads/
*.iml
web/.pnpm-debug.log
web/pnpm-lock.yaml
# binary files
*.exe
# SQLite database files
*.db
*.sqlite
*.sqlite3

View File

@ -87,12 +87,12 @@ func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath stri
"v1": newPath,
"v2": newMethod,
}).Error
e := casbinService.Casbin()
err = e.LoadPolicy()
if err != nil {
return err
}
return err
e := casbinService.Casbin()
return e.LoadPolicy()
}
//@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 关闭
// 对文件名进行加密存储
ext := filepath.Ext(file.Filename)
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 {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
// Delete the object from MinIO
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
err := m.Client.RemoveObject(ctx, m.bucket, key, minio.RemoveObjectOptions{})
return err
}