vendor: add qingstor-sdk-go for QingStor

This commit is contained in:
wuyu
2017-08-04 17:09:28 +01:00
committed by Nick Craig-Wood
parent f682002b84
commit 466dd22b44
136 changed files with 15952 additions and 1 deletions
File diff suppressed because it is too large Load Diff
+266
View File
@@ -0,0 +1,266 @@
// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------
package service
import (
"time"
)
// String returns a pointer to the given string value.
func String(v string) *string {
return &v
}
// StringValue returns the value of the given string pointer or
// "" if the pointer is nil.
func StringValue(v *string) string {
if v != nil {
return *v
}
return ""
}
// StringSlice converts a slice of string values into a slice of
// string pointers
func StringSlice(src []string) []*string {
dst := make([]*string, len(src))
for i := 0; i < len(src); i++ {
dst[i] = &(src[i])
}
return dst
}
// StringValueSlice converts a slice of string pointers into a slice of
// string values
func StringValueSlice(src []*string) []string {
dst := make([]string, len(src))
for i := 0; i < len(src); i++ {
if src[i] != nil {
dst[i] = *(src[i])
}
}
return dst
}
// StringMap converts a string map of string values into a string
// map of string pointers
func StringMap(src map[string]string) map[string]*string {
dst := make(map[string]*string)
for k, val := range src {
v := val
dst[k] = &v
}
return dst
}
// StringValueMap converts a string map of string pointers into a string
// map of string values
func StringValueMap(src map[string]*string) map[string]string {
dst := make(map[string]string)
for k, val := range src {
if val != nil {
dst[k] = *val
}
}
return dst
}
// Bool returns a pointer to the given bool value.
func Bool(v bool) *bool {
return &v
}
// BoolValue returns the value of the given bool pointer or
// false if the pointer is nil.
func BoolValue(v *bool) bool {
if v != nil {
return *v
}
return false
}
// BoolSlice converts a slice of bool values into a slice of
// bool pointers
func BoolSlice(src []bool) []*bool {
dst := make([]*bool, len(src))
for i := 0; i < len(src); i++ {
dst[i] = &(src[i])
}
return dst
}
// BoolValueSlice converts a slice of bool pointers into a slice of
// bool values
func BoolValueSlice(src []*bool) []bool {
dst := make([]bool, len(src))
for i := 0; i < len(src); i++ {
if src[i] != nil {
dst[i] = *(src[i])
}
}
return dst
}
// BoolMap converts a string map of bool values into a string
// map of bool pointers
func BoolMap(src map[string]bool) map[string]*bool {
dst := make(map[string]*bool)
for k, val := range src {
v := val
dst[k] = &v
}
return dst
}
// BoolValueMap converts a string map of bool pointers into a string
// map of bool values
func BoolValueMap(src map[string]*bool) map[string]bool {
dst := make(map[string]bool)
for k, val := range src {
if val != nil {
dst[k] = *val
}
}
return dst
}
// Int returns a pointer to the given int value.
func Int(v int) *int {
return &v
}
// IntValue returns the value of the given int pointer or
// 0 if the pointer is nil.
func IntValue(v *int) int {
if v != nil {
return *v
}
return 0
}
// IntSlice converts a slice of int values into a slice of
// int pointers
func IntSlice(src []int) []*int {
dst := make([]*int, len(src))
for i := 0; i < len(src); i++ {
dst[i] = &(src[i])
}
return dst
}
// IntValueSlice converts a slice of int pointers into a slice of
// int values
func IntValueSlice(src []*int) []int {
dst := make([]int, len(src))
for i := 0; i < len(src); i++ {
if src[i] != nil {
dst[i] = *(src[i])
}
}
return dst
}
// IntMap converts a string map of int values into a string
// map of int pointers
func IntMap(src map[string]int) map[string]*int {
dst := make(map[string]*int)
for k, val := range src {
v := val
dst[k] = &v
}
return dst
}
// IntValueMap converts a string map of int pointers into a string
// map of int values
func IntValueMap(src map[string]*int) map[string]int {
dst := make(map[string]int)
for k, val := range src {
if val != nil {
dst[k] = *val
}
}
return dst
}
// Time returns a pointer to the given time.Time value.
func Time(v time.Time) *time.Time {
return &v
}
// TimeValue returns the value of the given time.Time pointer or
// time.Time{} if the pointer is nil.
func TimeValue(v *time.Time) time.Time {
if v != nil {
return *v
}
return time.Time{}
}
// TimeUnixMilli returns a Unix timestamp in milliseconds from "January 1, 1970 UTC".
// The result is undefined if the Unix time cannot be represented by an int64.
// Which includes calling TimeUnixMilli on a zero Time is undefined.
//
// See Go stdlib https://golang.org/pkg/time/#Time.UnixNano for more information.
func TimeUnixMilli(t time.Time) int64 {
return t.UnixNano() / int64(time.Millisecond/time.Nanosecond)
}
// TimeSlice converts a slice of time.Time values into a slice of
// time.Time pointers
func TimeSlice(src []time.Time) []*time.Time {
dst := make([]*time.Time, len(src))
for i := 0; i < len(src); i++ {
dst[i] = &(src[i])
}
return dst
}
// TimeValueSlice converts a slice of time.Time pointers into a slice of
// time.Time values
func TimeValueSlice(src []*time.Time) []time.Time {
dst := make([]time.Time, len(src))
for i := 0; i < len(src); i++ {
if src[i] != nil {
dst[i] = *(src[i])
}
}
return dst
}
// TimeMap converts a string map of time.Time values into a string
// map of time.Time pointers
func TimeMap(src map[string]time.Time) map[string]*time.Time {
dst := make(map[string]*time.Time)
for k, val := range src {
v := val
dst[k] = &v
}
return dst
}
// TimeValueMap converts a string map of time.Time pointers into a string
// map of time.Time values
func TimeValueMap(src map[string]*time.Time) map[string]time.Time {
dst := make(map[string]time.Time)
for k, val := range src {
if val != nil {
dst[k] = *val
}
}
return dst
}
+311
View File
@@ -0,0 +1,311 @@
// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------
package service
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var testCasesStringSlice = [][]string{
{"a", "b", "c", "d", "e"},
{"a", "b", "", "", "e"},
}
func TestStringSlice(t *testing.T) {
for idx, in := range testCasesStringSlice {
if in == nil {
continue
}
out := StringSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := StringValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesStringValueSlice = [][]*string{
{String("a"), String("b"), nil, String("c")},
}
func TestStringValueSlice(t *testing.T) {
for idx, in := range testCasesStringValueSlice {
if in == nil {
continue
}
out := StringValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := StringSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesStringMap = []map[string]string{
{"a": "1", "b": "2", "c": "3"},
}
func TestStringMap(t *testing.T) {
for idx, in := range testCasesStringMap {
if in == nil {
continue
}
out := StringMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := StringValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesBoolSlice = [][]bool{
{true, true, false, false},
}
func TestBoolSlice(t *testing.T) {
for idx, in := range testCasesBoolSlice {
if in == nil {
continue
}
out := BoolSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := BoolValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesBoolValueSlice = [][]*bool{}
func TestBoolValueSlice(t *testing.T) {
for idx, in := range testCasesBoolValueSlice {
if in == nil {
continue
}
out := BoolValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := BoolSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesBoolMap = []map[string]bool{
{"a": true, "b": false, "c": true},
}
func TestBoolMap(t *testing.T) {
for idx, in := range testCasesBoolMap {
if in == nil {
continue
}
out := BoolMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := BoolValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesIntSlice = [][]int{
{1, 2, 3, 4},
}
func TestIntSlice(t *testing.T) {
for idx, in := range testCasesIntSlice {
if in == nil {
continue
}
out := IntSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := IntValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesIntValueSlice = [][]*int{}
func TestIntValueSlice(t *testing.T) {
for idx, in := range testCasesIntValueSlice {
if in == nil {
continue
}
out := IntValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := IntSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesIntMap = []map[string]int{
{"a": 3, "b": 2, "c": 1},
}
func TestIntMap(t *testing.T) {
for idx, in := range testCasesIntMap {
if in == nil {
continue
}
out := IntMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := IntValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesTimeSlice = [][]time.Time{
{time.Now(), time.Now().AddDate(100, 0, 0)},
}
func TestTimeSlice(t *testing.T) {
for idx, in := range testCasesTimeSlice {
if in == nil {
continue
}
out := TimeSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := TimeValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesTimeValueSlice = [][]*time.Time{}
func TestTimeValueSlice(t *testing.T) {
for idx, in := range testCasesTimeValueSlice {
if in == nil {
continue
}
out := TimeValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := TimeSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesTimeMap = []map[string]time.Time{
{"a": time.Now().AddDate(-100, 0, 0), "b": time.Now()},
}
func TestTimeMap(t *testing.T) {
for idx, in := range testCasesTimeMap {
if in == nil {
continue
}
out := TimeMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := TimeValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
+926
View File
@@ -0,0 +1,926 @@
// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------
package service
import (
"fmt"
"io"
"time"
"github.com/yunify/qingstor-sdk-go/config"
"github.com/yunify/qingstor-sdk-go/request"
"github.com/yunify/qingstor-sdk-go/request/data"
"github.com/yunify/qingstor-sdk-go/request/errors"
)
var _ fmt.State
var _ io.Reader
var _ time.Time
var _ config.Config
// AbortMultipartUpload does Abort multipart upload.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/abort_multipart_upload.html
func (s *Bucket) AbortMultipartUpload(objectKey string, input *AbortMultipartUploadInput) (*AbortMultipartUploadOutput, error) {
r, x, err := s.AbortMultipartUploadRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// AbortMultipartUploadRequest creates request and output object of AbortMultipartUpload.
func (s *Bucket) AbortMultipartUploadRequest(objectKey string, input *AbortMultipartUploadInput) (*request.Request, *AbortMultipartUploadOutput, error) {
if input == nil {
input = &AbortMultipartUploadInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "Abort Multipart Upload",
RequestMethod: "DELETE",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
204, // Object multipart deleted
},
}
s.Properties.ObjectKey = &objectKey
x := &AbortMultipartUploadOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// AbortMultipartUploadInput presents input for AbortMultipartUpload.
type AbortMultipartUploadInput struct {
// Object multipart upload ID
UploadID *string `json:"upload_id" name:"upload_id" location:"params"` // Required
}
// Validate validates the input for AbortMultipartUpload.
func (v *AbortMultipartUploadInput) Validate() error {
if v.UploadID == nil {
return errors.ParameterRequiredError{
ParameterName: "UploadID",
ParentName: "AbortMultipartUploadInput",
}
}
return nil
}
// AbortMultipartUploadOutput presents output for AbortMultipartUpload.
type AbortMultipartUploadOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
}
// CompleteMultipartUpload does Complete multipart upload.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/complete_multipart_upload.html
func (s *Bucket) CompleteMultipartUpload(objectKey string, input *CompleteMultipartUploadInput) (*CompleteMultipartUploadOutput, error) {
r, x, err := s.CompleteMultipartUploadRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// CompleteMultipartUploadRequest creates request and output object of CompleteMultipartUpload.
func (s *Bucket) CompleteMultipartUploadRequest(objectKey string, input *CompleteMultipartUploadInput) (*request.Request, *CompleteMultipartUploadOutput, error) {
if input == nil {
input = &CompleteMultipartUploadInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "Complete multipart upload",
RequestMethod: "POST",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
201, // Object created
},
}
s.Properties.ObjectKey = &objectKey
x := &CompleteMultipartUploadOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// CompleteMultipartUploadInput presents input for CompleteMultipartUpload.
type CompleteMultipartUploadInput struct {
// Object multipart upload ID
UploadID *string `json:"upload_id" name:"upload_id" location:"params"` // Required
// MD5sum of the object part
ETag *string `json:"ETag,omitempty" name:"ETag" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
// Encryption key of the object
XQSEncryptionCustomerKey *string `json:"X-QS-Encryption-Customer-Key,omitempty" name:"X-QS-Encryption-Customer-Key" location:"headers"`
// MD5sum of encryption key
XQSEncryptionCustomerKeyMD5 *string `json:"X-QS-Encryption-Customer-Key-MD5,omitempty" name:"X-QS-Encryption-Customer-Key-MD5" location:"headers"`
// Object parts
ObjectParts []*ObjectPartType `json:"object_parts,omitempty" name:"object_parts" location:"elements"`
}
// Validate validates the input for CompleteMultipartUpload.
func (v *CompleteMultipartUploadInput) Validate() error {
if v.UploadID == nil {
return errors.ParameterRequiredError{
ParameterName: "UploadID",
ParentName: "CompleteMultipartUploadInput",
}
}
if len(v.ObjectParts) > 0 {
for _, property := range v.ObjectParts {
if err := property.Validate(); err != nil {
return err
}
}
}
return nil
}
// CompleteMultipartUploadOutput presents output for CompleteMultipartUpload.
type CompleteMultipartUploadOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
}
// DeleteObject does Delete the object.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/delete.html
func (s *Bucket) DeleteObject(objectKey string) (*DeleteObjectOutput, error) {
r, x, err := s.DeleteObjectRequest(objectKey)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// DeleteObjectRequest creates request and output object of DeleteObject.
func (s *Bucket) DeleteObjectRequest(objectKey string) (*request.Request, *DeleteObjectOutput, error) {
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "DELETE Object",
RequestMethod: "DELETE",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
204, // Object deleted
},
}
s.Properties.ObjectKey = &objectKey
x := &DeleteObjectOutput{}
r, err := request.New(o, nil, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// DeleteObjectOutput presents output for DeleteObject.
type DeleteObjectOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
}
// GetObject does Retrieve the object.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/get.html
func (s *Bucket) GetObject(objectKey string, input *GetObjectInput) (*GetObjectOutput, error) {
r, x, err := s.GetObjectRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// GetObjectRequest creates request and output object of GetObject.
func (s *Bucket) GetObjectRequest(objectKey string, input *GetObjectInput) (*request.Request, *GetObjectOutput, error) {
if input == nil {
input = &GetObjectInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "GET Object",
RequestMethod: "GET",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
200, // OK
206, // Partial content
304, // Not modified
412, // Precondition failed
},
}
s.Properties.ObjectKey = &objectKey
x := &GetObjectOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// GetObjectInput presents input for GetObject.
type GetObjectInput struct {
// Specified the Cache-Control response header
ResponseCacheControl *string `json:"response-cache-control,omitempty" name:"response-cache-control" location:"params"`
// Specified the Content-Disposition response header
ResponseContentDisposition *string `json:"response-content-disposition,omitempty" name:"response-content-disposition" location:"params"`
// Specified the Content-Encoding response header
ResponseContentEncoding *string `json:"response-content-encoding,omitempty" name:"response-content-encoding" location:"params"`
// Specified the Content-Language response header
ResponseContentLanguage *string `json:"response-content-language,omitempty" name:"response-content-language" location:"params"`
// Specified the Content-Type response header
ResponseContentType *string `json:"response-content-type,omitempty" name:"response-content-type" location:"params"`
// Specified the Expires response header
ResponseExpires *string `json:"response-expires,omitempty" name:"response-expires" location:"params"`
// Check whether the ETag matches
IfMatch *string `json:"If-Match,omitempty" name:"If-Match" location:"headers"`
// Check whether the object has been modified
IfModifiedSince *time.Time `json:"If-Modified-Since,omitempty" name:"If-Modified-Since" format:"RFC 822" location:"headers"`
// Check whether the ETag does not match
IfNoneMatch *string `json:"If-None-Match,omitempty" name:"If-None-Match" location:"headers"`
// Check whether the object has not been modified
IfUnmodifiedSince *time.Time `json:"If-Unmodified-Since,omitempty" name:"If-Unmodified-Since" format:"RFC 822" location:"headers"`
// Specified range of the object
Range *string `json:"Range,omitempty" name:"Range" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
// Encryption key of the object
XQSEncryptionCustomerKey *string `json:"X-QS-Encryption-Customer-Key,omitempty" name:"X-QS-Encryption-Customer-Key" location:"headers"`
// MD5sum of encryption key
XQSEncryptionCustomerKeyMD5 *string `json:"X-QS-Encryption-Customer-Key-MD5,omitempty" name:"X-QS-Encryption-Customer-Key-MD5" location:"headers"`
}
// Validate validates the input for GetObject.
func (v *GetObjectInput) Validate() error {
return nil
}
// GetObjectOutput presents output for GetObject.
type GetObjectOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
// The response body
Body io.ReadCloser `location:"body"`
// Object content length
ContentLength *int64 `json:"Content-Length,omitempty" name:"Content-Length" location:"headers"`
// Range of response data content
ContentRange *string `json:"Content-Range,omitempty" name:"Content-Range" location:"headers"`
// MD5sum of the object
ETag *string `json:"ETag,omitempty" name:"ETag" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
}
// HeadObject does Check whether the object exists and available.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/head.html
func (s *Bucket) HeadObject(objectKey string, input *HeadObjectInput) (*HeadObjectOutput, error) {
r, x, err := s.HeadObjectRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// HeadObjectRequest creates request and output object of HeadObject.
func (s *Bucket) HeadObjectRequest(objectKey string, input *HeadObjectInput) (*request.Request, *HeadObjectOutput, error) {
if input == nil {
input = &HeadObjectInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "HEAD Object",
RequestMethod: "HEAD",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
200, // OK
},
}
s.Properties.ObjectKey = &objectKey
x := &HeadObjectOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// HeadObjectInput presents input for HeadObject.
type HeadObjectInput struct {
// Check whether the ETag matches
IfMatch *string `json:"If-Match,omitempty" name:"If-Match" location:"headers"`
// Check whether the object has been modified
IfModifiedSince *time.Time `json:"If-Modified-Since,omitempty" name:"If-Modified-Since" format:"RFC 822" location:"headers"`
// Check whether the ETag does not match
IfNoneMatch *string `json:"If-None-Match,omitempty" name:"If-None-Match" location:"headers"`
// Check whether the object has not been modified
IfUnmodifiedSince *time.Time `json:"If-Unmodified-Since,omitempty" name:"If-Unmodified-Since" format:"RFC 822" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
// Encryption key of the object
XQSEncryptionCustomerKey *string `json:"X-QS-Encryption-Customer-Key,omitempty" name:"X-QS-Encryption-Customer-Key" location:"headers"`
// MD5sum of encryption key
XQSEncryptionCustomerKeyMD5 *string `json:"X-QS-Encryption-Customer-Key-MD5,omitempty" name:"X-QS-Encryption-Customer-Key-MD5" location:"headers"`
}
// Validate validates the input for HeadObject.
func (v *HeadObjectInput) Validate() error {
return nil
}
// HeadObjectOutput presents output for HeadObject.
type HeadObjectOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
// Object content length
ContentLength *int64 `json:"Content-Length,omitempty" name:"Content-Length" location:"headers"`
// Object content type
ContentType *string `json:"Content-Type,omitempty" name:"Content-Type" location:"headers"`
// MD5sum of the object
ETag *string `json:"ETag,omitempty" name:"ETag" location:"headers"`
LastModified *time.Time `json:"Last-Modified,omitempty" name:"Last-Modified" format:"RFC 822" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
}
// InitiateMultipartUpload does Initial multipart upload on the object.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/initiate_multipart_upload.html
func (s *Bucket) InitiateMultipartUpload(objectKey string, input *InitiateMultipartUploadInput) (*InitiateMultipartUploadOutput, error) {
r, x, err := s.InitiateMultipartUploadRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// InitiateMultipartUploadRequest creates request and output object of InitiateMultipartUpload.
func (s *Bucket) InitiateMultipartUploadRequest(objectKey string, input *InitiateMultipartUploadInput) (*request.Request, *InitiateMultipartUploadOutput, error) {
if input == nil {
input = &InitiateMultipartUploadInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "Initiate Multipart Upload",
RequestMethod: "POST",
RequestURI: "/<bucket-name>/<object-key>?uploads",
StatusCodes: []int{
200, // OK
},
}
s.Properties.ObjectKey = &objectKey
x := &InitiateMultipartUploadOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// InitiateMultipartUploadInput presents input for InitiateMultipartUpload.
type InitiateMultipartUploadInput struct {
// Object content type
ContentType *string `json:"Content-Type,omitempty" name:"Content-Type" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
// Encryption key of the object
XQSEncryptionCustomerKey *string `json:"X-QS-Encryption-Customer-Key,omitempty" name:"X-QS-Encryption-Customer-Key" location:"headers"`
// MD5sum of encryption key
XQSEncryptionCustomerKeyMD5 *string `json:"X-QS-Encryption-Customer-Key-MD5,omitempty" name:"X-QS-Encryption-Customer-Key-MD5" location:"headers"`
}
// Validate validates the input for InitiateMultipartUpload.
func (v *InitiateMultipartUploadInput) Validate() error {
return nil
}
// InitiateMultipartUploadOutput presents output for InitiateMultipartUpload.
type InitiateMultipartUploadOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
// Bucket name
Bucket *string `json:"bucket,omitempty" name:"bucket" location:"elements"`
// Object key
Key *string `json:"key,omitempty" name:"key" location:"elements"`
// Object multipart upload ID
UploadID *string `json:"upload_id,omitempty" name:"upload_id" location:"elements"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
}
// ListMultipart does List object parts.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/list_multipart.html
func (s *Bucket) ListMultipart(objectKey string, input *ListMultipartInput) (*ListMultipartOutput, error) {
r, x, err := s.ListMultipartRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// ListMultipartRequest creates request and output object of ListMultipart.
func (s *Bucket) ListMultipartRequest(objectKey string, input *ListMultipartInput) (*request.Request, *ListMultipartOutput, error) {
if input == nil {
input = &ListMultipartInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "List Multipart",
RequestMethod: "GET",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
200, // OK
},
}
s.Properties.ObjectKey = &objectKey
x := &ListMultipartOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// ListMultipartInput presents input for ListMultipart.
type ListMultipartInput struct {
// Limit results count
Limit *int `json:"limit,omitempty" name:"limit" location:"params"`
// Object multipart upload part number
PartNumberMarker *int `json:"part_number_marker,omitempty" name:"part_number_marker" location:"params"`
// Object multipart upload ID
UploadID *string `json:"upload_id" name:"upload_id" location:"params"` // Required
}
// Validate validates the input for ListMultipart.
func (v *ListMultipartInput) Validate() error {
if v.UploadID == nil {
return errors.ParameterRequiredError{
ParameterName: "UploadID",
ParentName: "ListMultipartInput",
}
}
return nil
}
// ListMultipartOutput presents output for ListMultipart.
type ListMultipartOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
// Object multipart count
Count *int `json:"count,omitempty" name:"count" location:"elements"`
// Object parts
ObjectParts []*ObjectPartType `json:"object_parts,omitempty" name:"object_parts" location:"elements"`
}
// OptionsObject does Check whether the object accepts a origin with method and header.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/options.html
func (s *Bucket) OptionsObject(objectKey string, input *OptionsObjectInput) (*OptionsObjectOutput, error) {
r, x, err := s.OptionsObjectRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// OptionsObjectRequest creates request and output object of OptionsObject.
func (s *Bucket) OptionsObjectRequest(objectKey string, input *OptionsObjectInput) (*request.Request, *OptionsObjectOutput, error) {
if input == nil {
input = &OptionsObjectInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "OPTIONS Object",
RequestMethod: "OPTIONS",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
200, // OK
},
}
s.Properties.ObjectKey = &objectKey
x := &OptionsObjectOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// OptionsObjectInput presents input for OptionsObject.
type OptionsObjectInput struct {
// Request headers
AccessControlRequestHeaders *string `json:"Access-Control-Request-Headers,omitempty" name:"Access-Control-Request-Headers" location:"headers"`
// Request method
AccessControlRequestMethod *string `json:"Access-Control-Request-Method" name:"Access-Control-Request-Method" location:"headers"` // Required
// Request origin
Origin *string `json:"Origin" name:"Origin" location:"headers"` // Required
}
// Validate validates the input for OptionsObject.
func (v *OptionsObjectInput) Validate() error {
if v.AccessControlRequestMethod == nil {
return errors.ParameterRequiredError{
ParameterName: "AccessControlRequestMethod",
ParentName: "OptionsObjectInput",
}
}
if v.Origin == nil {
return errors.ParameterRequiredError{
ParameterName: "Origin",
ParentName: "OptionsObjectInput",
}
}
return nil
}
// OptionsObjectOutput presents output for OptionsObject.
type OptionsObjectOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
// Allowed headers
AccessControlAllowHeaders *string `json:"Access-Control-Allow-Headers,omitempty" name:"Access-Control-Allow-Headers" location:"headers"`
// Allowed methods
AccessControlAllowMethods *string `json:"Access-Control-Allow-Methods,omitempty" name:"Access-Control-Allow-Methods" location:"headers"`
// Allowed origin
AccessControlAllowOrigin *string `json:"Access-Control-Allow-Origin,omitempty" name:"Access-Control-Allow-Origin" location:"headers"`
// Expose headers
AccessControlExposeHeaders *string `json:"Access-Control-Expose-Headers,omitempty" name:"Access-Control-Expose-Headers" location:"headers"`
// Max age
AccessControlMaxAge *string `json:"Access-Control-Max-Age,omitempty" name:"Access-Control-Max-Age" location:"headers"`
}
// PutObject does Upload the object.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/put.html
func (s *Bucket) PutObject(objectKey string, input *PutObjectInput) (*PutObjectOutput, error) {
r, x, err := s.PutObjectRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// PutObjectRequest creates request and output object of PutObject.
func (s *Bucket) PutObjectRequest(objectKey string, input *PutObjectInput) (*request.Request, *PutObjectOutput, error) {
if input == nil {
input = &PutObjectInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "PUT Object",
RequestMethod: "PUT",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
201, // Object created
},
}
s.Properties.ObjectKey = &objectKey
x := &PutObjectOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// PutObjectInput presents input for PutObject.
type PutObjectInput struct {
// Object content size
ContentLength *int64 `json:"Content-Length" name:"Content-Length" location:"headers"` // Required
// Object MD5sum
ContentMD5 *string `json:"Content-MD5,omitempty" name:"Content-MD5" location:"headers"`
// Object content type
ContentType *string `json:"Content-Type,omitempty" name:"Content-Type" location:"headers"`
// Used to indicate that particular server behaviors are required by the client
Expect *string `json:"Expect,omitempty" name:"Expect" location:"headers"`
// Copy source, format (/<bucket-name>/<object-key>)
XQSCopySource *string `json:"X-QS-Copy-Source,omitempty" name:"X-QS-Copy-Source" location:"headers"`
// Encryption algorithm of the object
XQSCopySourceEncryptionCustomerAlgorithm *string `json:"X-QS-Copy-Source-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Copy-Source-Encryption-Customer-Algorithm" location:"headers"`
// Encryption key of the object
XQSCopySourceEncryptionCustomerKey *string `json:"X-QS-Copy-Source-Encryption-Customer-Key,omitempty" name:"X-QS-Copy-Source-Encryption-Customer-Key" location:"headers"`
// MD5sum of encryption key
XQSCopySourceEncryptionCustomerKeyMD5 *string `json:"X-QS-Copy-Source-Encryption-Customer-Key-MD5,omitempty" name:"X-QS-Copy-Source-Encryption-Customer-Key-MD5" location:"headers"`
// Check whether the copy source matches
XQSCopySourceIfMatch *string `json:"X-QS-Copy-Source-If-Match,omitempty" name:"X-QS-Copy-Source-If-Match" location:"headers"`
// Check whether the copy source has been modified
XQSCopySourceIfModifiedSince *time.Time `json:"X-QS-Copy-Source-If-Modified-Since,omitempty" name:"X-QS-Copy-Source-If-Modified-Since" format:"RFC 822" location:"headers"`
// Check whether the copy source does not match
XQSCopySourceIfNoneMatch *string `json:"X-QS-Copy-Source-If-None-Match,omitempty" name:"X-QS-Copy-Source-If-None-Match" location:"headers"`
// Check whether the copy source has not been modified
XQSCopySourceIfUnmodifiedSince *time.Time `json:"X-QS-Copy-Source-If-Unmodified-Since,omitempty" name:"X-QS-Copy-Source-If-Unmodified-Since" format:"RFC 822" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
// Encryption key of the object
XQSEncryptionCustomerKey *string `json:"X-QS-Encryption-Customer-Key,omitempty" name:"X-QS-Encryption-Customer-Key" location:"headers"`
// MD5sum of encryption key
XQSEncryptionCustomerKeyMD5 *string `json:"X-QS-Encryption-Customer-Key-MD5,omitempty" name:"X-QS-Encryption-Customer-Key-MD5" location:"headers"`
// Check whether fetch target object has not been modified
XQSFetchIfUnmodifiedSince *time.Time `json:"X-QS-Fetch-If-Unmodified-Since,omitempty" name:"X-QS-Fetch-If-Unmodified-Since" format:"RFC 822" location:"headers"`
// Fetch source, should be a valid url
XQSFetchSource *string `json:"X-QS-Fetch-Source,omitempty" name:"X-QS-Fetch-Source" location:"headers"`
// Move source, format (/<bucket-name>/<object-key>)
XQSMoveSource *string `json:"X-QS-Move-Source,omitempty" name:"X-QS-Move-Source" location:"headers"`
// The request body
Body io.Reader `location:"body"`
}
// Validate validates the input for PutObject.
func (v *PutObjectInput) Validate() error {
return nil
}
// PutObjectOutput presents output for PutObject.
type PutObjectOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
}
// UploadMultipart does Upload object multipart.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/object/multipart/upload_multipart.html
func (s *Bucket) UploadMultipart(objectKey string, input *UploadMultipartInput) (*UploadMultipartOutput, error) {
r, x, err := s.UploadMultipartRequest(objectKey, input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// UploadMultipartRequest creates request and output object of UploadMultipart.
func (s *Bucket) UploadMultipartRequest(objectKey string, input *UploadMultipartInput) (*request.Request, *UploadMultipartOutput, error) {
if input == nil {
input = &UploadMultipartInput{}
}
o := &data.Operation{
Config: s.Config,
Properties: s.Properties,
APIName: "Upload Multipart",
RequestMethod: "PUT",
RequestURI: "/<bucket-name>/<object-key>",
StatusCodes: []int{
201, // Object multipart created
},
}
s.Properties.ObjectKey = &objectKey
x := &UploadMultipartOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// UploadMultipartInput presents input for UploadMultipart.
type UploadMultipartInput struct {
// Object multipart upload part number
PartNumber *int `json:"part_number" name:"part_number" default:"0" location:"params"` // Required
// Object multipart upload ID
UploadID *string `json:"upload_id" name:"upload_id" location:"params"` // Required
// Object multipart content length
ContentLength *int64 `json:"Content-Length,omitempty" name:"Content-Length" location:"headers"`
// Object multipart content MD5sum
ContentMD5 *string `json:"Content-MD5,omitempty" name:"Content-MD5" location:"headers"`
// Encryption algorithm of the object
XQSEncryptionCustomerAlgorithm *string `json:"X-QS-Encryption-Customer-Algorithm,omitempty" name:"X-QS-Encryption-Customer-Algorithm" location:"headers"`
// Encryption key of the object
XQSEncryptionCustomerKey *string `json:"X-QS-Encryption-Customer-Key,omitempty" name:"X-QS-Encryption-Customer-Key" location:"headers"`
// MD5sum of encryption key
XQSEncryptionCustomerKeyMD5 *string `json:"X-QS-Encryption-Customer-Key-MD5,omitempty" name:"X-QS-Encryption-Customer-Key-MD5" location:"headers"`
// The request body
Body io.Reader `location:"body"`
}
// Validate validates the input for UploadMultipart.
func (v *UploadMultipartInput) Validate() error {
if v.PartNumber == nil {
return errors.ParameterRequiredError{
ParameterName: "PartNumber",
ParentName: "UploadMultipartInput",
}
}
if v.UploadID == nil {
return errors.ParameterRequiredError{
ParameterName: "UploadID",
ParentName: "UploadMultipartInput",
}
}
return nil
}
// UploadMultipartOutput presents output for UploadMultipart.
type UploadMultipartOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
}
+104
View File
@@ -0,0 +1,104 @@
// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------
// Package service provides QingStor Service API (API Version 2016-01-06)
package service
import (
"github.com/yunify/qingstor-sdk-go/config"
"github.com/yunify/qingstor-sdk-go/request"
"github.com/yunify/qingstor-sdk-go/request/data"
)
// Service QingStor provides low-cost and reliable online storage service with unlimited storage space, high read and write performance, high reliability and data safety, fine-grained access control, and easy to use API.
type Service struct {
Config *config.Config
}
// Init initializes a new service.
func Init(c *config.Config) (*Service, error) {
return &Service{Config: c}, nil
}
// ListBuckets does Retrieve the bucket list.
// Documentation URL: https://docs.qingcloud.com/qingstor/api/service/get.html
func (s *Service) ListBuckets(input *ListBucketsInput) (*ListBucketsOutput, error) {
r, x, err := s.ListBucketsRequest(input)
if err != nil {
return x, err
}
err = r.Send()
if err != nil {
return nil, err
}
requestID := r.HTTPResponse.Header.Get("X-Qs-Request-Id")
x.RequestID = &requestID
return x, err
}
// ListBucketsRequest creates request and output object of ListBuckets.
func (s *Service) ListBucketsRequest(input *ListBucketsInput) (*request.Request, *ListBucketsOutput, error) {
if input == nil {
input = &ListBucketsInput{}
}
o := &data.Operation{
Config: s.Config,
APIName: "Get Service",
RequestMethod: "GET",
RequestURI: "/",
StatusCodes: []int{
200, // OK
},
}
x := &ListBucketsOutput{}
r, err := request.New(o, input, x)
if err != nil {
return nil, nil, err
}
return r, x, nil
}
// ListBucketsInput presents input for ListBuckets.
type ListBucketsInput struct {
// Limits results to buckets that in the location
Location *string `json:"Location,omitempty" name:"Location" location:"headers"`
}
// Validate validates the input for ListBuckets.
func (v *ListBucketsInput) Validate() error {
return nil
}
// ListBucketsOutput presents output for ListBuckets.
type ListBucketsOutput struct {
StatusCode *int `location:"statusCode"`
RequestID *string `location:"requestID"`
// Buckets information
Buckets []*BucketType `json:"buckets,omitempty" name:"buckets" location:"elements"`
// Bucket count
Count *int `json:"count,omitempty" name:"count" location:"elements"`
}
+463
View File
@@ -0,0 +1,463 @@
// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------
package service
import (
"fmt"
"time"
"github.com/yunify/qingstor-sdk-go/request/errors"
)
// Properties presents the service properties.
type Properties struct {
// Bucket name
BucketName *string `json:"bucket-name" name:"bucket-name"` // Required
// Object key
ObjectKey *string `json:"object-key" name:"object-key"` // Required
// QingCloud Zone ID
Zone *string `json:"zone" name:"zone"`
}
// ACLType presents ACL.
type ACLType struct {
Grantee *GranteeType `json:"grantee" name:"grantee"` // Required
// Permission for this grantee
// Permission's available values: READ, WRITE, FULL_CONTROL
Permission *string `json:"permission" name:"permission"` // Required
}
// Validate validates the ACL.
func (v *ACLType) Validate() error {
if v.Grantee != nil {
if err := v.Grantee.Validate(); err != nil {
return err
}
}
if v.Grantee == nil {
return errors.ParameterRequiredError{
ParameterName: "Grantee",
ParentName: "ACL",
}
}
if v.Permission == nil {
return errors.ParameterRequiredError{
ParameterName: "Permission",
ParentName: "ACL",
}
}
if v.Permission != nil {
permissionValidValues := []string{"READ", "WRITE", "FULL_CONTROL"}
permissionParameterValue := fmt.Sprint(*v.Permission)
permissionIsValid := false
for _, value := range permissionValidValues {
if value == permissionParameterValue {
permissionIsValid = true
}
}
if !permissionIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Permission",
ParameterValue: permissionParameterValue,
AllowedValues: permissionValidValues,
}
}
}
return nil
}
// BucketType presents Bucket.
type BucketType struct {
// Created time of the bucket
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// QingCloud Zone ID
Location *string `json:"location,omitempty" name:"location"`
// Bucket name
Name *string `json:"name,omitempty" name:"name"`
// URL to access the bucket
URL *string `json:"url,omitempty" name:"url"`
}
// Validate validates the Bucket.
func (v *BucketType) Validate() error {
return nil
}
// ConditionType presents Condition.
type ConditionType struct {
IPAddress *IPAddressType `json:"ip_address,omitempty" name:"ip_address"`
IsNull *IsNullType `json:"is_null,omitempty" name:"is_null"`
NotIPAddress *NotIPAddressType `json:"not_ip_address,omitempty" name:"not_ip_address"`
StringLike *StringLikeType `json:"string_like,omitempty" name:"string_like"`
StringNotLike *StringNotLikeType `json:"string_not_like,omitempty" name:"string_not_like"`
}
// Validate validates the Condition.
func (v *ConditionType) Validate() error {
if v.IPAddress != nil {
if err := v.IPAddress.Validate(); err != nil {
return err
}
}
if v.IsNull != nil {
if err := v.IsNull.Validate(); err != nil {
return err
}
}
if v.NotIPAddress != nil {
if err := v.NotIPAddress.Validate(); err != nil {
return err
}
}
if v.StringLike != nil {
if err := v.StringLike.Validate(); err != nil {
return err
}
}
if v.StringNotLike != nil {
if err := v.StringNotLike.Validate(); err != nil {
return err
}
}
return nil
}
// CORSRuleType presents CORSRule.
type CORSRuleType struct {
// Allowed headers
AllowedHeaders []*string `json:"allowed_headers,omitempty" name:"allowed_headers"`
// Allowed methods
AllowedMethods []*string `json:"allowed_methods" name:"allowed_methods"` // Required
// Allowed origin
AllowedOrigin *string `json:"allowed_origin" name:"allowed_origin"` // Required
// Expose headers
ExposeHeaders []*string `json:"expose_headers,omitempty" name:"expose_headers"`
// Max age seconds
MaxAgeSeconds *int `json:"max_age_seconds,omitempty" name:"max_age_seconds"`
}
// Validate validates the CORSRule.
func (v *CORSRuleType) Validate() error {
if len(v.AllowedMethods) == 0 {
return errors.ParameterRequiredError{
ParameterName: "AllowedMethods",
ParentName: "CORSRule",
}
}
if v.AllowedOrigin == nil {
return errors.ParameterRequiredError{
ParameterName: "AllowedOrigin",
ParentName: "CORSRule",
}
}
return nil
}
// GranteeType presents Grantee.
type GranteeType struct {
// Grantee user ID
ID *string `json:"id,omitempty" name:"id"`
// Grantee group name
Name *string `json:"name,omitempty" name:"name"`
// Grantee type
// Type's available values: user, group
Type *string `json:"type" name:"type"` // Required
}
// Validate validates the Grantee.
func (v *GranteeType) Validate() error {
if v.Type == nil {
return errors.ParameterRequiredError{
ParameterName: "Type",
ParentName: "Grantee",
}
}
if v.Type != nil {
typeValidValues := []string{"user", "group"}
typeParameterValue := fmt.Sprint(*v.Type)
typeIsValid := false
for _, value := range typeValidValues {
if value == typeParameterValue {
typeIsValid = true
}
}
if !typeIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Type",
ParameterValue: typeParameterValue,
AllowedValues: typeValidValues,
}
}
}
return nil
}
// IPAddressType presents IPAddress.
type IPAddressType struct {
// Source IP
SourceIP []*string `json:"source_ip,omitempty" name:"source_ip"`
}
// Validate validates the IPAddress.
func (v *IPAddressType) Validate() error {
return nil
}
// IsNullType presents IsNull.
type IsNullType struct {
// Refer url
Referer *bool `json:"Referer,omitempty" name:"Referer"`
}
// Validate validates the IsNull.
func (v *IsNullType) Validate() error {
return nil
}
// KeyType presents Key.
type KeyType struct {
// Object created time
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// Whether this key is encrypted
Encrypted *bool `json:"encrypted,omitempty" name:"encrypted"`
// MD5sum of the object
Etag *string `json:"etag,omitempty" name:"etag"`
// Object key
Key *string `json:"key,omitempty" name:"key"`
// MIME type of the object
MimeType *string `json:"mime_type,omitempty" name:"mime_type"`
// Last modified time in unix time format
Modified *int `json:"modified,omitempty" name:"modified"`
// Object content size
Size *int64 `json:"size,omitempty" name:"size"`
}
// Validate validates the Key.
func (v *KeyType) Validate() error {
return nil
}
// KeyDeleteErrorType presents KeyDeleteError.
type KeyDeleteErrorType struct {
// Error code
Code *string `json:"code,omitempty" name:"code"`
// Object key
Key *string `json:"key,omitempty" name:"key"`
// Error message
Message *string `json:"message,omitempty" name:"message"`
}
// Validate validates the KeyDeleteError.
func (v *KeyDeleteErrorType) Validate() error {
return nil
}
// NotIPAddressType presents NotIPAddress.
type NotIPAddressType struct {
// Source IP
SourceIP []*string `json:"source_ip,omitempty" name:"source_ip"`
}
// Validate validates the NotIPAddress.
func (v *NotIPAddressType) Validate() error {
return nil
}
// ObjectPartType presents ObjectPart.
type ObjectPartType struct {
// Object part created time
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// MD5sum of the object part
Etag *string `json:"etag,omitempty" name:"etag"`
// Object part number
PartNumber *int `json:"part_number" name:"part_number" default:"0"` // Required
// Object part size
Size *int64 `json:"size,omitempty" name:"size"`
}
// Validate validates the ObjectPart.
func (v *ObjectPartType) Validate() error {
if v.PartNumber == nil {
return errors.ParameterRequiredError{
ParameterName: "PartNumber",
ParentName: "ObjectPart",
}
}
return nil
}
// OwnerType presents Owner.
type OwnerType struct {
// User ID
ID *string `json:"id,omitempty" name:"id"`
// Username
Name *string `json:"name,omitempty" name:"name"`
}
// Validate validates the Owner.
func (v *OwnerType) Validate() error {
return nil
}
// StatementType presents Statement.
type StatementType struct {
// QingStor API methods
Action []*string `json:"action" name:"action"` // Required
Condition *ConditionType `json:"condition,omitempty" name:"condition"`
// Statement effect
// Effect's available values: allow, deny
Effect *string `json:"effect" name:"effect"` // Required
// Bucket policy id, must be unique
ID *string `json:"id" name:"id"` // Required
// The resources to apply bucket policy
Resource []*string `json:"resource,omitempty" name:"resource"`
// The user to apply bucket policy
User []*string `json:"user" name:"user"` // Required
}
// Validate validates the Statement.
func (v *StatementType) Validate() error {
if len(v.Action) == 0 {
return errors.ParameterRequiredError{
ParameterName: "Action",
ParentName: "Statement",
}
}
if v.Condition != nil {
if err := v.Condition.Validate(); err != nil {
return err
}
}
if v.Effect == nil {
return errors.ParameterRequiredError{
ParameterName: "Effect",
ParentName: "Statement",
}
}
if v.Effect != nil {
effectValidValues := []string{"allow", "deny"}
effectParameterValue := fmt.Sprint(*v.Effect)
effectIsValid := false
for _, value := range effectValidValues {
if value == effectParameterValue {
effectIsValid = true
}
}
if !effectIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Effect",
ParameterValue: effectParameterValue,
AllowedValues: effectValidValues,
}
}
}
if v.ID == nil {
return errors.ParameterRequiredError{
ParameterName: "ID",
ParentName: "Statement",
}
}
if len(v.User) == 0 {
return errors.ParameterRequiredError{
ParameterName: "User",
ParentName: "Statement",
}
}
return nil
}
// StringLikeType presents StringLike.
type StringLikeType struct {
// Refer url
Referer []*string `json:"Referer,omitempty" name:"Referer"`
}
// Validate validates the StringLike.
func (v *StringLikeType) Validate() error {
return nil
}
// StringNotLikeType presents StringNotLike.
type StringNotLikeType struct {
// Refer url
Referer []*string `json:"Referer,omitempty" name:"Referer"`
}
// Validate validates the StringNotLike.
func (v *StringNotLikeType) Validate() error {
return nil
}
// UploadsType presents Uploads.
type UploadsType struct {
// Object part created time
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// Object key
Key *string `json:"key,omitempty" name:"key"`
// Object upload id
UploadID *string `json:"upload_id,omitempty" name:"upload_id"`
}
// Validate validates the Uploads.
func (v *UploadsType) Validate() error {
return nil
}