处理返回的 cancel 函数, 避免 context 泄露
不处理 cancel 相关返回函数,会造成 context 一直停留在 background. the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak
This commit is contained in:
parent
fe6830b77a
commit
14014e9af4
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue