/
bucket_accessmonitor.go
54 lines (46 loc) · 1.3 KB
/
bucket_accessmonitor.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
package sample
import (
"fmt"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
// BucketAccessMonitorSample how to set, get the bucket access monitor.
func BucketAccessMonitorSample() {
// New client
client, err := oss.New(endpoint, accessID, accessKey)
if err != nil {
HandleError(err)
}
access := oss.PutBucketAccessMonitor{
Status: "Enabled",
}
// put bucket access monitor
err = client.PutBucketAccessMonitor(bucketName, access)
if err != nil {
HandleError(err)
}
fmt.Println("put bucket access monitor success!")
// put bucket access monitor in xml format
xml := `<?xml version="1.0" encoding="UTF-8"?>
<AccessMonitorConfiguration>
<Status>Enabled</Status>
</AccessMonitorConfiguration>
`
err = client.PutBucketAccessMonitorXml(bucketName, xml)
if err != nil {
HandleError(err)
}
fmt.Println("put bucket access monitor in xml format success!")
// get bucket access monitor
result, err := client.GetBucketAccessMonitor(bucketName)
if err != nil {
HandleError(err)
}
fmt.Printf("bucket access monitor config is:%s\n", result.Status)
// get bucket access monitor in xml format
xmlData, err := client.GetBucketAccessMonitorXml(bucketName)
if err != nil {
HandleError(err)
}
fmt.Printf("bucket access monitor config is:%s\n", xmlData)
fmt.Println("BucketAccessMonitorSample completed")
}