github.com/aliyun/aliyun-oss-go-sdk@v3.0.2+incompatible/sample/bucket_tagging.go (about) 1 package sample 2 3 import ( 4 "fmt" 5 "github.com/aliyun/aliyun-oss-go-sdk/oss" 6 ) 7 8 // BucketTaggingSample shows how to set,get and the bucket stat. 9 func BucketTaggingSample() { 10 // New client 11 client, err := oss.New(endpoint, accessID, accessKey) 12 if err != nil { 13 HandleError(err) 14 } 15 // Set bucket tagging 16 tag1 := oss.Tag{ 17 Key: "key1", 18 Value: "value1", 19 } 20 tag2 := oss.Tag{ 21 Key: "key2", 22 Value: "value2", 23 } 24 tag3 := oss.Tag{ 25 Key: "key3", 26 Value: "value2", 27 } 28 tagging := oss.Tagging{ 29 Tags: []oss.Tag{tag1, tag2, tag3}, 30 } 31 err = client.SetBucketTagging(bucketName, tagging) 32 if err != nil { 33 HandleError(err) 34 } 35 36 //Get bucket tagging 37 ret, err := client.GetBucketTagging(bucketName) 38 if err != nil { 39 HandleError(err) 40 } 41 fmt.Println("Tag length: ", len(ret.Tags)) 42 for _, tag := range ret.Tags { 43 fmt.Printf("Tag Key: %s\n", tag.Key) 44 fmt.Printf("Tag Value: %s\n", tag.Value) 45 } 46 //Delete one tagging 47 err = client.DeleteBucketTagging(bucketName, oss.AddParam("tagging", "key1")) 48 if err != nil { 49 HandleError(err) 50 } 51 // Delete many tagging 52 err = client.DeleteBucketTagging(bucketName, oss.AddParam("tagging", "key1,key2")) 53 if err != nil { 54 HandleError(err) 55 } 56 // Delete all tagging 57 err = client.DeleteBucketTagging(bucketName) 58 if err != nil { 59 HandleError(err) 60 } 61 fmt.Println("BucketTaggingSample completed") 62 }