forked from tencentyun/cos-go-sdk-v5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket_website.go
77 lines (65 loc) · 2.29 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
package cos
import (
"context"
"encoding/xml"
"net/http"
)
type WebsiteRoutingRule struct {
ConditionErrorCode string `xml:"Condition>HttpErrorCodeReturnedEquals,omitempty"`
ConditionPrefix string `xml:"Condition>KeyPrefixEquals,omitempty"`
RedirectProtocol string `xml:"Redirect>Protocol,omitempty"`
RedirectReplaceKey string `xml:"Redirect>ReplaceKeyWith,omitempty"`
RedirectReplaceKeyPrefix string `xml:"Redirect>ReplaceKeyPrefixWith,omitempty"`
}
type WebsiteRoutingRules struct {
Rules []WebsiteRoutingRule `xml:"RoutingRule,omitempty"`
}
type AutoAddressing struct {
Status string `xml:"Status,omitempty"`
}
type ErrorDocument struct {
Key string `xml:"Key,omitempty"`
OriginalHttpStatus string `xml:"OriginalHttpStatus,omitempty"`
}
type RedirectRequestsProtocol struct {
Protocol string `xml:"Protocol,omitempty"`
}
type BucketPutWebsiteOptions struct {
XMLName xml.Name `xml:"WebsiteConfiguration"`
Index string `xml:"IndexDocument>Suffix"`
RedirectProtocol *RedirectRequestsProtocol `xml:"RedirectAllRequestsTo,omitempty"`
AutoAddressing *AutoAddressing `xml:"AutoAddressing,omitempty"`
Error *ErrorDocument `xml:"ErrorDocument,omitempty"`
RoutingRules *WebsiteRoutingRules `xml:"RoutingRules,omitempty"`
}
type BucketGetWebsiteResult BucketPutWebsiteOptions
func (s *BucketService) PutWebsite(ctx context.Context, opt *BucketPutWebsiteOptions) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?website",
method: http.MethodPut,
body: opt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}
func (s *BucketService) GetWebsite(ctx context.Context) (*BucketGetWebsiteResult, *Response, error) {
var res BucketGetWebsiteResult
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?website",
method: http.MethodGet,
result: &res,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return &res, resp, err
}
func (s *BucketService) DeleteWebsite(ctx context.Context) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?website",
method: http.MethodDelete,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}