-
Notifications
You must be signed in to change notification settings - Fork 231
/
bucket_website.go
104 lines (91 loc) · 2.41 KB
/
bucket_website.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package sample
import (
"fmt"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
// BucketWebsiteSample shows how to set, get and delete the bucket website.
func BucketWebsiteSample() {
// 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)
}
//Define bucket website indexWebsite or errorWebsite
var indexWebsite = "myindex.html"
var errorWebsite = "myerror.html"
// Set bucket website indexWebsite or errorWebsite
err = client.SetBucketWebsite(bucketName, indexWebsite, errorWebsite)
if err != nil {
HandleError(err)
}
bEnable := true
bDisable := false
// Define one website detail
ruleOk := oss.RoutingRule{
RuleNumber: 1,
Condition: oss.Condition{
KeyPrefixEquals: "abc",
HTTPErrorCodeReturnedEquals: 404,
IncludeHeader: []oss.IncludeHeader{
oss.IncludeHeader{
Key: "host",
Equals: "test.oss-cn-beijing-internal.aliyuncs.com",
},
},
},
Redirect: oss.Redirect{
RedirectType: "Mirror",
PassQueryString: &bDisable,
MirrorURL: "http://www.test.com/",
MirrorPassQueryString: &bEnable,
MirrorFollowRedirect: &bEnable,
MirrorCheckMd5: &bDisable,
MirrorHeaders: oss.MirrorHeaders{
PassAll: &bEnable,
Pass: []string{"key1", "key2"},
Remove: []string{"remove1", "remove2"},
Set: []oss.MirrorHeaderSet{
oss.MirrorHeaderSet{
Key: "setKey1",
Value: "setValue1",
},
},
},
},
}
wxmlDetail := oss.WebsiteXML{}
wxmlDetail.RoutingRules = append(wxmlDetail.RoutingRules, ruleOk)
// Get website
res, err := client.GetBucketWebsite(bucketName)
if err != nil {
HandleError(err)
}
fmt.Println("Website IndexDocument:", res.IndexDocument.Suffix)
// Set bucket website detail
err = client.SetBucketWebsiteDetail(bucketName, wxmlDetail)
if err != nil {
HandleError(err)
}
// Get website Detail
res, err = client.GetBucketWebsite(bucketName)
if err != nil {
HandleError(err)
}
fmt.Println("Website Redirect type:", res.RoutingRules[0].Redirect.RedirectType)
// Delete Website
err = client.DeleteBucketWebsite(bucketName)
if err != nil {
HandleError(err)
}
// Delete bucket
err = client.DeleteBucket(bucketName)
if err != nil {
HandleError(err)
}
fmt.Println("BucketWebsiteSample completed")
}