forked from tencentyun/cos-go-sdk-v5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket_origin.go
91 lines (79 loc) · 2.9 KB
/
bucket_origin.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
package cos
import (
"context"
"encoding/xml"
"net/http"
)
type BucketPutOriginOptions struct {
XMLName xml.Name `xml:"OriginConfiguration"`
Rule []BucketOriginRule `xml:"OriginRule"`
}
type BucketOriginRule struct {
RulePriority int `xml:"RulePriority,omitempty"`
OriginType string `xml:"OriginType,omitempty"`
OriginCondition *BucketOriginCondition `xml:"OriginCondition,omitempty"`
OriginParameter *BucketOriginParameter `xml:"OriginParameter,omitempty"`
OriginInfo *BucketOriginInfo `xml:"OriginInfo,omitempty"`
}
type BucketOriginCondition struct {
HTTPStatusCode string `xml:"HTTPStatusCode,omitempty"`
Prefix string `xml:"Prefix,omitempty"`
}
type BucketOriginParameter struct {
Protocol string `xml:"Protocol,omitempty"`
FollowQueryString bool `xml:"FollowQueryString,omitempty"`
HttpHeader *BucketOriginHttpHeader `xml:"HttpHeader,omitempty"`
FollowRedirection bool `xml:"FollowRedirection,omitempty"`
HttpRedirectCode string `xml:"HttpRedirectCode,omitempty"`
CopyOriginData bool `xml:"CopyOriginData,omitempty"`
}
type BucketOriginHttpHeader struct {
// 目前还不支持 FollowAllHeaders
// FollowAllHeaders bool `xml:"FollowAllHeaders,omitempty"`
NewHttpHeaders []OriginHttpHeader `xml:"NewHttpHeaders>Header,omitempty"`
FollowHttpHeaders []OriginHttpHeader `xml:"FollowHttpHeaders>Header,omitempty"`
}
type OriginHttpHeader struct {
Key string `xml:"Key,omitempty"`
Value string `xml:"Value,omitempty"`
}
type BucketOriginInfo struct {
HostInfo string `xml:"HostInfo>HostName,omitempty"`
FileInfo *BucketOriginFileInfo `xml:"FileInfo,omitempty"`
}
type BucketOriginFileInfo struct {
PrefixDirective bool `xml:"PrefixDirective,omitempty"`
Prefix string `xml:"Prefix,omitempty"`
Suffix string `xml:"Suffix,omitempty"`
}
type BucketGetOriginResult BucketPutOriginOptions
func (s *BucketService) PutOrigin(ctx context.Context, opt *BucketPutOriginOptions) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?origin",
method: http.MethodPut,
body: opt,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}
func (s *BucketService) GetOrigin(ctx context.Context) (*BucketGetOriginResult, *Response, error) {
var res BucketGetOriginResult
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?origin",
method: http.MethodGet,
result: &res,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return &res, resp, err
}
func (s *BucketService) DeleteOrigin(ctx context.Context) (*Response, error) {
sendOpt := &sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/?origin",
method: http.MethodDelete,
}
resp, err := s.client.doRetry(ctx, sendOpt)
return resp, err
}