-
Notifications
You must be signed in to change notification settings - Fork 86
/
bucket.go
71 lines (64 loc) · 2.29 KB
/
bucket.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package types
import (
"encoding/json"
"fmt"
"github.com/dustin/go-humanize"
"github.com/journeymidnight/yig/api/datatype"
"github.com/journeymidnight/yig/api/datatype/policy"
"time"
)
const (
VersionEnabled = "Enabled"
VersionDisabled = "Disabled"
VersionSuspended = "Suspended"
)
type Bucket struct {
Name string
// Date and time when the bucket was created,
// should be serialized into format "2006-01-02T15:04:05.000Z"
CreateTime time.Time
OwnerId string
CORS datatype.Cors
ACL datatype.Acl
Lifecycle datatype.Lifecycle
Policy policy.Policy
Website datatype.WebsiteConfiguration
Versioning string // actually enum: Disabled/Enabled/Suspended
Usage int64
}
func (b *Bucket) String() (s string) {
s += "Name: " + b.Name + "\t"
s += "CreateTime: " + b.CreateTime.Format(CREATE_TIME_LAYOUT) + "\t"
s += "OwnerId: " + b.OwnerId + "\t"
s += "CORS: " + fmt.Sprintf("%+v", b.CORS) + "\t"
s += "ACL: " + fmt.Sprintf("%+v", b.ACL) + "\t"
s += "LifeCycle: " + fmt.Sprintf("%+v", b.Lifecycle) + "\t"
s += "Policy: " + fmt.Sprintf("%+v", b.Policy) + "\t"
s += "Website: " + fmt.Sprintf("%+v", b.Website) + "\t"
s += "Version: " + b.Versioning + "\t"
s += "Usage: " + humanize.Bytes(uint64(b.Usage)) + "\t"
return
}
//Tidb related function
func (b Bucket) GetUpdateSql() (string, []interface{}) {
acl, _ := json.Marshal(b.ACL)
cors, _ := json.Marshal(b.CORS)
lc, _ := json.Marshal(b.Lifecycle)
bucket_policy, _ := json.Marshal(b.Policy)
website, _ := json.Marshal(b.Website)
sql := "update buckets set bucketname=?,acl=?,policy=?,cors=?,lc=?,website=?,uid=?,versioning=? where bucketname=?"
args := []interface{}{b.Name, acl, bucket_policy, cors, lc, website, b.OwnerId, b.Versioning, b.Name}
return sql, args
}
func (b Bucket) GetCreateSql() (string, []interface{}) {
acl, _ := json.Marshal(b.ACL)
cors, _ := json.Marshal(b.CORS)
lc, _ := json.Marshal(b.Lifecycle)
bucket_policy, _ := json.Marshal(b.Policy)
website, _ := json.Marshal(b.Website)
createTime := b.CreateTime.Format(TIME_LAYOUT_TIDB)
sql := "insert into buckets(bucketname,acl,cors,lc,uid,policy,website,createtime,usages,versioning) " +
"values(?,?,?,?,?,?,?,?,?,?);"
args := []interface{}{b.Name, acl, cors, lc, b.OwnerId, bucket_policy, website, createTime, b.Usage, b.Versioning}
return sql, args
}