github.com/aliyun/aliyun-oss-go-sdk@v3.0.2+incompatible/sample/bucket_accessmonitor.go (about) 1 package sample 2 3 import ( 4 "fmt" 5 "github.com/aliyun/aliyun-oss-go-sdk/oss" 6 ) 7 8 // BucketAccessMonitorSample how to set, get the bucket access monitor. 9 func BucketAccessMonitorSample() { 10 // New client 11 client, err := oss.New(endpoint, accessID, accessKey) 12 if err != nil { 13 HandleError(err) 14 } 15 access := oss.PutBucketAccessMonitor{ 16 Status: "Enabled", 17 } 18 // put bucket access monitor 19 err = client.PutBucketAccessMonitor(bucketName, access) 20 if err != nil { 21 HandleError(err) 22 } 23 fmt.Println("put bucket access monitor success!") 24 25 // put bucket access monitor in xml format 26 27 xml := `<?xml version="1.0" encoding="UTF-8"?> 28 <AccessMonitorConfiguration> 29 <Status>Enabled</Status> 30 </AccessMonitorConfiguration> 31 ` 32 err = client.PutBucketAccessMonitorXml(bucketName, xml) 33 if err != nil { 34 HandleError(err) 35 } 36 fmt.Println("put bucket access monitor in xml format success!") 37 38 // get bucket access monitor 39 result, err := client.GetBucketAccessMonitor(bucketName) 40 if err != nil { 41 HandleError(err) 42 } 43 fmt.Printf("bucket access monitor config is:%s\n", result.Status) 44 45 // get bucket access monitor in xml format 46 xmlData, err := client.GetBucketAccessMonitorXml(bucketName) 47 if err != nil { 48 HandleError(err) 49 } 50 fmt.Printf("bucket access monitor config is:%s\n", xmlData) 51 52 fmt.Println("BucketAccessMonitorSample completed") 53 54 }