-
Notifications
You must be signed in to change notification settings - Fork 234
/
bucket_style.go
62 lines (53 loc) · 1.55 KB
/
bucket_style.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"
)
// BucketStyleSample shows how to set,get list and delete the bucket's style.
func BucketStyleSample() {
// New client
client, err := oss.New(endpoint, accessID, accessKey)
if err != nil {
HandleError(err)
}
// Create the bucket with default parameters
err = client.CreateBucket(bucketName)
if err != nil {
HandleError(err)
}
// Get bucket's style.
styleName := "image-style"
style, err := client.GetBucketStyle(bucketName, styleName)
if err != nil {
HandleError(err)
}
fmt.Printf("Style Name:%s\n", style.Name)
fmt.Printf("Style Name:%s\n", style.Content)
fmt.Printf("Style Create Time:%s\n", style.CreateTime)
fmt.Printf("Style Last Modify Time:%s\n", style.LastModifyTime)
// Set bucket's style.
styleContent := "image/resize,p_50"
err = client.PutBucketStyle(bucketName, styleName, styleContent)
if err != nil {
HandleError(err)
}
fmt.Println("Put Bucket Style Success!")
// List bucket's style
list, err := client.ListBucketStyle(bucketName)
if err != nil {
HandleError(err)
}
for _, styleInfo := range list.Style {
fmt.Printf("Style Name:%s\n", styleInfo.Name)
fmt.Printf("Style Name:%s\n", styleInfo.Content)
fmt.Printf("Style Create Time:%s\n", styleInfo.CreateTime)
fmt.Printf("Style Last Modify Time:%s\n", styleInfo.LastModifyTime)
}
// Delete bucket's style
err = client.DeleteBucketStyle(bucketName, styleName)
if err != nil {
HandleError(err)
}
fmt.Println("Bucket Style Delete Success!")
fmt.Println("BucketStyleSample completed")
}