-
Notifications
You must be signed in to change notification settings - Fork 200
/
delete.go
46 lines (39 loc) · 1.34 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package object
import (
"fmt"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/qshell/v2/iqshell/common/alert"
"github.com/qiniu/qshell/v2/iqshell/common/data"
"github.com/qiniu/qshell/v2/iqshell/storage/object/batch"
)
type DeleteApiInfo struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
DeleteAfterDays int `json:"delete_after_days"`
IsDeleteAfter bool `json:"-"`
Condition batch.OperationCondition `json:"condition"`
}
func (d *DeleteApiInfo) GetBucket() string {
return d.Bucket
}
func (d *DeleteApiInfo) ToOperation() (string, *data.CodeError) {
if len(d.Bucket) == 0 || len(d.Key) == 0 {
return "", alert.CannotEmptyError("delete operation bucket or key", "")
}
condition := batch.OperationConditionURI(d.Condition)
if d.IsDeleteAfter {
if d.DeleteAfterDays < 0 {
return "", alert.Error("DeleteAfterDays can't be smaller than 0", "")
} else {
return storage.URIDeleteAfterDays(d.Bucket, d.Key, d.DeleteAfterDays) + condition, nil
}
} else {
return storage.URIDelete(d.Bucket, d.Key) + condition, nil
}
}
func (d *DeleteApiInfo) WorkId() string {
return fmt.Sprintf("Delete|%s|%s", d.Bucket, d.Key)
}
func Delete(info *DeleteApiInfo) (*batch.OperationResult, *data.CodeError) {
return batch.One(info)
}