-
Notifications
You must be signed in to change notification settings - Fork 231
/
bucket_tagging.go
62 lines (59 loc) · 1.32 KB
/
bucket_tagging.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
package sample
import (
"fmt"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
// BucketTaggingSample shows how to set,get and the bucket stat.
func BucketTaggingSample() {
// New client
client, err := oss.New(endpoint, accessID, accessKey)
if err != nil {
HandleError(err)
}
// Set bucket tagging
tag1 := oss.Tag{
Key: "key1",
Value: "value1",
}
tag2 := oss.Tag{
Key: "key2",
Value: "value2",
}
tag3 := oss.Tag{
Key: "key3",
Value: "value2",
}
tagging := oss.Tagging{
Tags: []oss.Tag{tag1, tag2, tag3},
}
err = client.SetBucketTagging(bucketName, tagging)
if err != nil {
HandleError(err)
}
//Get bucket tagging
ret, err := client.GetBucketTagging(bucketName)
if err != nil {
HandleError(err)
}
fmt.Println("Tag length: ", len(ret.Tags))
for _, tag := range ret.Tags {
fmt.Printf("Tag Key: %s\n", tag.Key)
fmt.Printf("Tag Value: %s\n", tag.Value)
}
//Delete one tagging
err = client.DeleteBucketTagging(bucketName, oss.AddParam("tagging", "key1"))
if err != nil {
HandleError(err)
}
// Delete many tagging
err = client.DeleteBucketTagging(bucketName, oss.AddParam("tagging", "key1,key2"))
if err != nil {
HandleError(err)
}
// Delete all tagging
err = client.DeleteBucketTagging(bucketName)
if err != nil {
HandleError(err)
}
fmt.Println("BucketTaggingSample completed")
}