|
| 1 | +package cos |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/xml" |
| 6 | + "net/http" |
| 7 | +) |
| 8 | + |
| 9 | +type BucketPutOriginOptions struct { |
| 10 | + XMLName xml.Name `xml:"OriginConfiguration"` |
| 11 | + Rule []BucketOriginRule `xml:"OriginRule"` |
| 12 | +} |
| 13 | + |
| 14 | +type BucketOriginRule struct { |
| 15 | + OriginType string `xml:"OriginType"` |
| 16 | + OriginCondition *BucketOriginCondition `xml:"OriginCondition"` |
| 17 | + OriginParameter *BucketOriginParameter `xml:"OriginParameter"` |
| 18 | + OriginInfo *BucketOriginInfo `xml:"OriginInfo"` |
| 19 | +} |
| 20 | + |
| 21 | +type BucketOriginCondition struct { |
| 22 | + HTTPStatusCode string `xml:"HTTPStatusCode,omitempty"` |
| 23 | + Prefix string `xml:"Prefix,omitempty"` |
| 24 | +} |
| 25 | + |
| 26 | +type BucketOriginParameter struct { |
| 27 | + Protocol string `xml:"Protocol,omitempty"` |
| 28 | + FollowQueryString bool `xml:"FollowQueryString,omitempty"` |
| 29 | + HttpHeader *BucketOriginHttpHeader `xml:"HttpHeader,omitempty"` |
| 30 | + FollowRedirection bool `xml:"FollowRedirection,omitempty"` |
| 31 | + HttpRedirectCode string `xml:"HttpRedirectCode,omitempty"` |
| 32 | + CopyOriginData bool `xml:"CopyOriginData,omitempty"` |
| 33 | +} |
| 34 | + |
| 35 | +type BucketOriginHttpHeader struct { |
| 36 | + // 目前还不支持 FollowAllHeaders |
| 37 | + // FollowAllHeaders bool `xml:"FollowAllHeaders,omitempty"` |
| 38 | + NewHttpHeaders []OriginHttpHeader `xml:"NewHttpHeaders>Header,omitempty"` |
| 39 | + FollowHttpHeaders []OriginHttpHeader `xml:"FollowHttpHeaders>Header,omitempty"` |
| 40 | +} |
| 41 | + |
| 42 | +type OriginHttpHeader struct { |
| 43 | + Key string `xml:"Key,omitempty"` |
| 44 | + Value string `xml:"Value,omitempty"` |
| 45 | +} |
| 46 | + |
| 47 | +type BucketOriginInfo struct { |
| 48 | + HostInfo string `xml:"HostInfo>HostName,omitempty"` |
| 49 | + FileInfo *BucketOriginFileInfo `xml:"FileInfo,omitempty"` |
| 50 | +} |
| 51 | +type BucketOriginFileInfo struct { |
| 52 | + PrefixDirective bool `xml:"PrefixDirective,omitempty"` |
| 53 | + Prefix string `xml:"Prefix,omitempty"` |
| 54 | + Suffix string `xml:"Suffix,omitempty"` |
| 55 | +} |
| 56 | + |
| 57 | +type BucketGetOriginResult BucketPutOriginOptions |
| 58 | + |
| 59 | +func (s *BucketService) PutOrigin(ctx context.Context, opt *BucketPutOriginOptions) (*Response, error) { |
| 60 | + sendOpt := &sendOptions{ |
| 61 | + baseURL: s.client.BaseURL.BucketURL, |
| 62 | + uri: "/?origin", |
| 63 | + method: http.MethodPut, |
| 64 | + body: opt, |
| 65 | + } |
| 66 | + resp, err := s.client.send(ctx, sendOpt) |
| 67 | + return resp, err |
| 68 | +} |
| 69 | + |
| 70 | +func (s *BucketService) GetOrigin(ctx context.Context) (*BucketGetOriginResult, *Response, error) { |
| 71 | + var res BucketGetOriginResult |
| 72 | + sendOpt := &sendOptions{ |
| 73 | + baseURL: s.client.BaseURL.BucketURL, |
| 74 | + uri: "/?origin", |
| 75 | + method: http.MethodGet, |
| 76 | + result: &res, |
| 77 | + } |
| 78 | + resp, err := s.client.send(ctx, sendOpt) |
| 79 | + return &res, resp, err |
| 80 | +} |
| 81 | + |
| 82 | +func (s *BucketService) DeleteOrigin(ctx context.Context) (*Response, error) { |
| 83 | + sendOpt := &sendOptions{ |
| 84 | + baseURL: s.client.BaseURL.BucketURL, |
| 85 | + uri: "/?origin", |
| 86 | + method: http.MethodDelete, |
| 87 | + } |
| 88 | + resp, err := s.client.send(ctx, sendOpt) |
| 89 | + return resp, err |
| 90 | +} |
0 commit comments