vendor: update all dependencies to latest versions
This commit is contained in:
+7
-7
@@ -20,25 +20,25 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http"
|
||||
|
||||
"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/config"
|
||||
"github.com/yunify/qingstor-sdk-go/request"
|
||||
"github.com/yunify/qingstor-sdk-go/request/data"
|
||||
)
|
||||
|
||||
var _ http.Header
|
||||
|
||||
{{if $service.Description}}// Service {{$service.Description}}{{end}}
|
||||
type Service struct {
|
||||
Config *config.Config
|
||||
Config *config.Config
|
||||
}
|
||||
|
||||
// Init initializes a new service.
|
||||
func Init(c *config.Config) (*Service, error) {
|
||||
return &Service{Config: c}, nil
|
||||
return &Service{Config: c}, nil
|
||||
}
|
||||
|
||||
{{range $_, $operation := $service.Operations}}
|
||||
{{template "RenderOperation" passThrough $service $operation}}
|
||||
{{template "RenderOperation" passThrough $service $operation}}
|
||||
{{end}}
|
||||
|
||||
+334
-334
@@ -1,391 +1,391 @@
|
||||
{{define "Type"}}
|
||||
{{- $typeName := index . 0 -}}
|
||||
{{- $disablePointer := index . 1 -}}
|
||||
{{- $typeName := index . 0 -}}
|
||||
{{- $disablePointer := index . 1 -}}
|
||||
|
||||
{{- if eq $typeName "string" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}string
|
||||
{{- else if eq $typeName "boolean" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}bool
|
||||
{{- else if eq $typeName "integer" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}int
|
||||
{{- else if eq $typeName "long" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}int64
|
||||
{{- else if eq $typeName "timestamp" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}time.Time
|
||||
{{- else if eq $typeName "binary" -}}
|
||||
io.Reader
|
||||
{{- else if eq $typeName "array" -}}
|
||||
interface{}
|
||||
{{- else if eq $typeName "object" -}}
|
||||
interface{}
|
||||
{{- else if eq $typeName "map" -}}
|
||||
interface{}
|
||||
{{- else if eq $typeName "any" -}}
|
||||
interface{}
|
||||
{{- else -}}
|
||||
*{{$typeName | camelCase}}Type
|
||||
{{- end -}}
|
||||
{{- if eq $typeName "string" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}string
|
||||
{{- else if eq $typeName "boolean" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}bool
|
||||
{{- else if eq $typeName "integer" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}int
|
||||
{{- else if eq $typeName "long" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}int64
|
||||
{{- else if eq $typeName "timestamp" -}}
|
||||
{{- if not $disablePointer -}}*{{- end -}}time.Time
|
||||
{{- else if eq $typeName "binary" -}}
|
||||
io.Reader
|
||||
{{- else if eq $typeName "array" -}}
|
||||
interface{}
|
||||
{{- else if eq $typeName "object" -}}
|
||||
interface{}
|
||||
{{- else if eq $typeName "map" -}}
|
||||
interface{}
|
||||
{{- else if eq $typeName "any" -}}
|
||||
interface{}
|
||||
{{- else -}}
|
||||
*{{$typeName | camelCase}}Type
|
||||
{{- end -}}
|
||||
{{end}}
|
||||
|
||||
{{define "PropertyType"}}
|
||||
{{- $property := index . 0 -}}
|
||||
{{- $disablePointer := index . 1 -}}
|
||||
{{- $property := index . 0 -}}
|
||||
{{- $disablePointer := index . 1 -}}
|
||||
|
||||
{{- if eq $property.Type "object" -}}
|
||||
{{template "Type" passThrough $property.ExtraType $disablePointer}}
|
||||
{{- else if eq $property.Type "array" -}}
|
||||
[]{{template "Type" passThrough $property.ExtraType $disablePointer}}
|
||||
{{- else if eq $property.Type "map" -}}
|
||||
map[string]{{template "Type" passThrough $property.ExtraType $disablePointer}}
|
||||
{{- else if eq $property.Type "any" -}}
|
||||
{{template "Type" passThrough $property.Type $disablePointer}}
|
||||
{{- else -}}
|
||||
{{template "Type" passThrough $property.Type $disablePointer}}
|
||||
{{- end -}}
|
||||
{{- if eq $property.Type "object" -}}
|
||||
{{template "Type" passThrough $property.ExtraType $disablePointer}}
|
||||
{{- else if eq $property.Type "array" -}}
|
||||
[]{{template "Type" passThrough $property.ExtraType $disablePointer}}
|
||||
{{- else if eq $property.Type "map" -}}
|
||||
map[string]{{template "Type" passThrough $property.ExtraType $disablePointer}}
|
||||
{{- else if eq $property.Type "any" -}}
|
||||
{{template "Type" passThrough $property.Type $disablePointer}}
|
||||
{{- else -}}
|
||||
{{template "Type" passThrough $property.Type $disablePointer}}
|
||||
{{- end -}}
|
||||
{{end}}
|
||||
|
||||
{{define "PropertyTags"}}
|
||||
{{- $property := . -}}
|
||||
{{- if $property.IsRequired -}}
|
||||
{{- printf `json:"%s"` ($property.Name | normalized) -}}
|
||||
{{- else -}}
|
||||
{{- printf `json:"%s,omitempty"` ($property.Name | normalized) -}}
|
||||
{{- end -}}
|
||||
{{- printf ` name:"%s"` ($property.Name | normalized) -}}
|
||||
{{- if $property.Format}}
|
||||
{{- printf ` format:"%s"` $property.Format -}}
|
||||
{{- end -}}
|
||||
{{- if $property.Default -}}
|
||||
{{- printf ` default:"%s"` $property.Default -}}
|
||||
{{- end -}}
|
||||
{{- $property := . -}}
|
||||
{{- if $property.IsRequired -}}
|
||||
{{- printf `json:"%s"` ($property.Name | normalized) -}}
|
||||
{{- else -}}
|
||||
{{- printf `json:"%s,omitempty"` ($property.Name | normalized) -}}
|
||||
{{- end -}}
|
||||
{{- printf ` name:"%s"` ($property.Name | normalized) -}}
|
||||
{{- if $property.Format}}
|
||||
{{- printf ` format:"%s"` $property.Format -}}
|
||||
{{- end -}}
|
||||
{{- if $property.Default -}}
|
||||
{{- printf ` default:"%s"` $property.Default -}}
|
||||
{{- end -}}
|
||||
{{end}}
|
||||
|
||||
{{define "PropertyTagsDashConnected"}}
|
||||
{{- $property := . -}}
|
||||
{{- printf `json:"%s"` ($property.Name | dashConnected) -}}
|
||||
{{- printf ` name:"%s"` ($property.Name | dashConnected) -}}
|
||||
{{- $property := . -}}
|
||||
{{- printf `json:"%s"` ($property.Name | dashConnected) -}}
|
||||
{{- printf ` name:"%s"` ($property.Name | dashConnected) -}}
|
||||
{{end}}
|
||||
|
||||
{{define "PropertyExtraTags"}}
|
||||
{{- $propertyExtraTags := . -}}
|
||||
{{- if $propertyExtraTags -}}
|
||||
{{- printf " %s" $propertyExtraTags -}}
|
||||
{{- end -}}
|
||||
{{- $propertyExtraTags := . -}}
|
||||
{{- if $propertyExtraTags -}}
|
||||
{{- printf " %s" $propertyExtraTags -}}
|
||||
{{- end -}}
|
||||
{{end}}
|
||||
|
||||
{{define "RenderProperties"}}
|
||||
{{- $customizedType := index . 0 -}}
|
||||
{{- $propertyExtraTags := index . 1 -}}
|
||||
{{- $operationName := index . 2 -}}
|
||||
{{- $customizedType := index . 0 -}}
|
||||
{{- $propertyExtraTags := index . 1 -}}
|
||||
{{- $operationName := index . 2 -}}
|
||||
|
||||
{{range $_, $property := $customizedType.Properties -}}
|
||||
{{if or (ne $operationName "Delete Multiple Objects") (ne $property.ID "Content-MD5") -}}
|
||||
{{if $property.Description -}}
|
||||
// {{$property.Description}}
|
||||
{{end -}}
|
||||
{{if $property.Enum -}}
|
||||
// {{$property.ID | camelCase}}'s available values: {{$property.Enum | commaConnected}}
|
||||
{{end -}}
|
||||
{{$property.ID | camelCase | upperFirst}}{{" " -}}
|
||||
{{template "PropertyType" passThrough $property false}}{{" " -}}
|
||||
`{{template "PropertyTags" $property}}{{template "PropertyExtraTags" $propertyExtraTags}}`{{" " -}}
|
||||
{{if $property.IsRequired -}}
|
||||
// Required
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
{{end}}
|
||||
{{range $_, $property := $customizedType.Properties -}}
|
||||
{{if or (ne $operationName "Delete Multiple Objects") (ne $property.ID "Content-MD5") -}}
|
||||
{{if $property.Description -}}
|
||||
// {{$property.Description}}
|
||||
{{end -}}
|
||||
{{if $property.Enum -}}
|
||||
// {{$property.ID | camelCase}}'s available values: {{$property.Enum | commaConnected}}
|
||||
{{end -}}
|
||||
{{$property.ID | camelCase | upperFirst}}{{" " -}}
|
||||
{{template "PropertyType" passThrough $property false}}{{" " -}}
|
||||
`{{template "PropertyTags" $property}}{{template "PropertyExtraTags" $propertyExtraTags}}`{{" " -}}
|
||||
{{if $property.IsRequired -}}
|
||||
// Required
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{define "RenderOperation"}}
|
||||
{{$service := index . 0}}
|
||||
{{$operation := index . 1}}
|
||||
{{$service := index . 0}}
|
||||
{{$operation := index . 1}}
|
||||
|
||||
{{$belongs := replace $service.Name "QingStor" "Service" -1}}
|
||||
{{$belongs := replace $belongs "Object" "Bucket" -1}}
|
||||
{{$opID := $operation.ID | camelCase}}
|
||||
{{$belongs := replace $service.Name "QingStor" "Service" -1}}
|
||||
{{$belongs := replace $belongs "Object" "Bucket" -1}}
|
||||
{{$opID := $operation.ID | camelCase}}
|
||||
|
||||
{{$isBucket := eq $service.Name "Bucket"}}
|
||||
{{$isObject := eq $service.Name "Object"}}
|
||||
{{$isBucket := eq $service.Name "Bucket"}}
|
||||
{{$isObject := eq $service.Name "Object"}}
|
||||
|
||||
{{$hasQuery := gt (len $operation.Request.Query.Properties) 0}}
|
||||
{{$hasHeaders := gt (len $operation.Request.Headers.Properties) 0}}
|
||||
{{$hasElements := gt (len $operation.Request.Elements.Properties) 0}}
|
||||
{{$hasStringBody := eq $operation.Request.Body.Type "string"}}
|
||||
{{$hasBinaryBody := eq $operation.Request.Body.Type "binary"}}
|
||||
{{$hasInput := or $hasQuery $hasHeaders $hasElements $hasStringBody $hasBinaryBody}}
|
||||
{{$hasQuery := gt (len $operation.Request.Query.Properties) 0}}
|
||||
{{$hasHeaders := gt (len $operation.Request.Headers.Properties) 0}}
|
||||
{{$hasElements := gt (len $operation.Request.Elements.Properties) 0}}
|
||||
{{$hasStringBody := eq $operation.Request.Body.Type "string"}}
|
||||
{{$hasBinaryBody := eq $operation.Request.Body.Type "binary"}}
|
||||
{{$hasInput := or $hasQuery $hasHeaders $hasElements $hasStringBody $hasBinaryBody}}
|
||||
|
||||
{{if $operation.Description -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
// {{replace $opID "Bucket" "" -1}} does {{$operation.Description}}
|
||||
{{else -}}
|
||||
// {{$opID}} does {{$operation.Description}}
|
||||
{{end -}}
|
||||
{{end -}}
|
||||
{{if $operation.DocumentationURL -}}
|
||||
// Documentation URL: {{$operation.DocumentationURL}}
|
||||
{{- end}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
func (s *{{$belongs}}) {{replace $opID "Bucket" "" -1 -}}(
|
||||
{{- if $isObject}}objectKey string,{{end -}}
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*{{$opID}}Output, error) {
|
||||
{{else -}}
|
||||
func (s *{{$belongs}}) {{$opID}}(
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*{{$opID}}Output, error) {
|
||||
{{end -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
r, x, err := s.{{replace $opID "Bucket" "" -1}}Request(
|
||||
{{- if $isObject}}objectKey,{{end -}}
|
||||
{{- if $hasInput}}input{{end -}}
|
||||
)
|
||||
{{else -}}
|
||||
r, x, err := s.{{$opID}}Request(
|
||||
{{- if $hasInput}}input{{end -}}
|
||||
)
|
||||
{{end}}
|
||||
if err != nil {
|
||||
return x, err
|
||||
}
|
||||
{{if $operation.Description -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
// {{replace $opID "Bucket" "" -1}} does {{$operation.Description}}
|
||||
{{else -}}
|
||||
// {{$opID}} does {{$operation.Description}}
|
||||
{{end -}}
|
||||
{{end -}}
|
||||
{{if $operation.DocumentationURL -}}
|
||||
// Documentation URL: {{$operation.DocumentationURL}}
|
||||
{{- end}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
func (s *{{$belongs}}) {{replace $opID "Bucket" "" -1 -}}(
|
||||
{{- if $isObject}}objectKey string,{{end -}}
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*{{$opID}}Output, error) {
|
||||
{{else -}}
|
||||
func (s *{{$belongs}}) {{$opID}}(
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*{{$opID}}Output, error) {
|
||||
{{end -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
r, x, err := s.{{replace $opID "Bucket" "" -1}}Request(
|
||||
{{- if $isObject}}objectKey,{{end -}}
|
||||
{{- if $hasInput}}input{{end -}}
|
||||
)
|
||||
{{else -}}
|
||||
r, x, err := s.{{$opID}}Request(
|
||||
{{- if $hasInput}}input{{end -}}
|
||||
)
|
||||
{{end}}
|
||||
if err != nil {
|
||||
return x, err
|
||||
}
|
||||
|
||||
err = r.Send()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = r.Send()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
requestID := r.HTTPResponse.Header.Get(http.CanonicalHeaderKey("X-QS-Request-ID"))
|
||||
x.RequestID = &requestID
|
||||
requestID := r.HTTPResponse.Header.Get(http.CanonicalHeaderKey("X-QS-Request-ID"))
|
||||
x.RequestID = &requestID
|
||||
|
||||
return x, err
|
||||
}
|
||||
return x, err
|
||||
}
|
||||
|
||||
{{if $operation.Description -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
// {{replace $opID "Bucket" "" -1}}Request creates request and output object of {{$opID}}.
|
||||
{{else -}}
|
||||
// {{$opID}}Request creates request and output object of {{$opID}}.
|
||||
{{end -}}
|
||||
{{end -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
func (s *{{$belongs}}) {{replace $opID "Bucket" "" -1 -}}Request(
|
||||
{{- if $isObject}}objectKey string,{{end -}}
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*request.Request, *{{$opID}}Output, error) {
|
||||
{{else -}}
|
||||
func (s *{{$belongs}}) {{$opID}}Request(
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*request.Request, *{{$opID}}Output, error) {
|
||||
{{end -}}
|
||||
{{if $hasInput}}
|
||||
if input == nil {
|
||||
input = &{{$opID}}Input{}
|
||||
}
|
||||
{{end}}
|
||||
{{$path := $operation.Request.Path}}
|
||||
{{$path := replace $path "{" "<" -1}}
|
||||
{{$path := replace $path "}" ">" -1}}
|
||||
{{$path := dashConnected $path}}
|
||||
{{if $operation.Description -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
// {{replace $opID "Bucket" "" -1}}Request creates request and output object of {{$opID}}.
|
||||
{{else -}}
|
||||
// {{$opID}}Request creates request and output object of {{$opID}}.
|
||||
{{end -}}
|
||||
{{end -}}
|
||||
{{if eq $belongs "Bucket" -}}
|
||||
func (s *{{$belongs}}) {{replace $opID "Bucket" "" -1 -}}Request(
|
||||
{{- if $isObject}}objectKey string,{{end -}}
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*request.Request, *{{$opID}}Output, error) {
|
||||
{{else -}}
|
||||
func (s *{{$belongs}}) {{$opID}}Request(
|
||||
{{- if $hasInput}}input *{{$opID}}Input{{end -}}
|
||||
) (*request.Request, *{{$opID}}Output, error) {
|
||||
{{end -}}
|
||||
{{if $hasInput}}
|
||||
if input == nil {
|
||||
input = &{{$opID}}Input{}
|
||||
}
|
||||
{{end}}
|
||||
{{$path := $operation.Request.Path}}
|
||||
{{$path := replace $path "{" "<" -1}}
|
||||
{{$path := replace $path "}" ">" -1}}
|
||||
{{$path := dashConnected $path}}
|
||||
|
||||
{{- if ne $belongs "Service"}}
|
||||
properties := *s.Properties
|
||||
{{- end}}
|
||||
{{if eq $service.Name "Object"}}
|
||||
properties.ObjectKey = &objectKey
|
||||
{{end}}
|
||||
{{- if ne $belongs "Service"}}
|
||||
properties := *s.Properties
|
||||
{{- end}}
|
||||
{{if eq $service.Name "Object"}}
|
||||
properties.ObjectKey = &objectKey
|
||||
{{end}}
|
||||
|
||||
o := &data.Operation{
|
||||
Config: s.Config,
|
||||
{{- if ne $belongs "Service"}}
|
||||
Properties: &properties,
|
||||
{{- end}}
|
||||
APIName: "{{$operation.Name}}",
|
||||
RequestMethod: "{{$operation.Request.Method}}",
|
||||
RequestURI: "{{$path}}",
|
||||
StatusCodes: []int{
|
||||
{{range $keyStatus, $valueStatus := $operation.Responses -}}
|
||||
{{- if $valueStatus.StatusCode -}}
|
||||
{{$valueStatus.StatusCode.Code}}, // {{$valueStatus.StatusCode.Description}}
|
||||
{{else}}
|
||||
200, // OK
|
||||
{{end -}}
|
||||
{{else}}
|
||||
200, // OK
|
||||
{{end -}}
|
||||
},
|
||||
}
|
||||
o := &data.Operation{
|
||||
Config: s.Config,
|
||||
{{- if ne $belongs "Service"}}
|
||||
Properties: &properties,
|
||||
{{- end}}
|
||||
APIName: "{{$operation.Name}}",
|
||||
RequestMethod: "{{$operation.Request.Method}}",
|
||||
RequestURI: "{{$path}}",
|
||||
StatusCodes: []int{
|
||||
{{range $keyStatus, $valueStatus := $operation.Responses -}}
|
||||
{{- if $valueStatus.StatusCode -}}
|
||||
{{$valueStatus.StatusCode.Code}}, // {{$valueStatus.StatusCode.Description}}
|
||||
{{else}}
|
||||
200, // OK
|
||||
{{end -}}
|
||||
{{else}}
|
||||
200, // OK
|
||||
{{end -}}
|
||||
},
|
||||
}
|
||||
|
||||
x := &{{$opID}}Output{}
|
||||
r, err := request.New(o, {{if $hasInput}}input{{else}}nil{{end}}, x)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
x := &{{$opID}}Output{}
|
||||
r, err := request.New(o, {{if $hasInput}}input{{else}}nil{{end}}, x)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return r, x, nil
|
||||
}
|
||||
return r, x, nil
|
||||
}
|
||||
|
||||
{{if $hasInput}}
|
||||
// {{$opID}}Input presents input for {{$opID}}.
|
||||
type {{$opID}}Input struct {
|
||||
{{- if $operation.Request.Query.Properties | len}}
|
||||
{{$data := $operation.Request.Query -}}
|
||||
{{template "RenderProperties" passThrough $data `location:"query"` $operation.Name}}
|
||||
{{end}}
|
||||
{{if $hasInput}}
|
||||
// {{$opID}}Input presents input for {{$opID}}.
|
||||
type {{$opID}}Input struct {
|
||||
{{- if $operation.Request.Query.Properties | len}}
|
||||
{{$data := $operation.Request.Query -}}
|
||||
{{template "RenderProperties" passThrough $data `location:"query"` $operation.Name}}
|
||||
{{end}}
|
||||
|
||||
{{- if $operation.Request.Headers.Properties | len}}
|
||||
{{$data := $operation.Request.Headers -}}
|
||||
{{template "RenderProperties" passThrough $data `location:"headers"` $operation.Name}}
|
||||
{{end}}
|
||||
{{- if $operation.Request.Headers.Properties | len}}
|
||||
{{$data := $operation.Request.Headers -}}
|
||||
{{template "RenderProperties" passThrough $data `location:"headers"` $operation.Name}}
|
||||
{{end}}
|
||||
|
||||
{{- if $operation.Request.Elements.Properties | len}}
|
||||
{{$data := $operation.Request.Elements -}}
|
||||
{{template "RenderProperties" passThrough $data `location:"elements"` $operation.Name}}
|
||||
{{end}}
|
||||
{{- if $operation.Request.Elements.Properties | len}}
|
||||
{{$data := $operation.Request.Elements -}}
|
||||
{{template "RenderProperties" passThrough $data `location:"elements"` $operation.Name}}
|
||||
{{end}}
|
||||
|
||||
{{- if eq $operation.Request.Body.Type "string"}}
|
||||
{{if $operation.Request.Body.Description -}}
|
||||
// {{$operation.Request.Body.Description}}
|
||||
{{- end}}
|
||||
Body string `location:"body"`
|
||||
{{else if eq $operation.Request.Body.Type "binary"}}
|
||||
{{if $operation.Request.Body.Description -}}
|
||||
// {{$operation.Request.Body.Description}}
|
||||
{{- end}}
|
||||
Body io.Reader `location:"body"`
|
||||
{{end}}
|
||||
}
|
||||
{{- if eq $operation.Request.Body.Type "string"}}
|
||||
{{if $operation.Request.Body.Description -}}
|
||||
// {{$operation.Request.Body.Description}}
|
||||
{{- end}}
|
||||
Body string `location:"body"`
|
||||
{{else if eq $operation.Request.Body.Type "binary"}}
|
||||
{{if $operation.Request.Body.Description -}}
|
||||
// {{$operation.Request.Body.Description}}
|
||||
{{- end}}
|
||||
Body io.Reader `location:"body"`
|
||||
{{end}}
|
||||
}
|
||||
|
||||
// Validate validates the input for {{$opID}}.
|
||||
func (v *{{$opID}}Input) Validate() error {
|
||||
{{template "ValidateCustomizedType" passThrough $operation.Request.Query $operation.Name}}
|
||||
{{template "ValidateCustomizedType" passThrough $operation.Request.Headers $operation.Name}}
|
||||
{{template "ValidateCustomizedType" passThrough $operation.Request.Elements $operation.Name}}
|
||||
// Validate validates the input for {{$opID}}.
|
||||
func (v *{{$opID}}Input) Validate() error {
|
||||
{{template "ValidateCustomizedType" passThrough $operation.Request.Query $operation.Name}}
|
||||
{{template "ValidateCustomizedType" passThrough $operation.Request.Headers $operation.Name}}
|
||||
{{template "ValidateCustomizedType" passThrough $operation.Request.Elements $operation.Name}}
|
||||
|
||||
return nil
|
||||
}
|
||||
{{end}}
|
||||
return nil
|
||||
}
|
||||
{{end}}
|
||||
|
||||
// {{$opID}}Output presents output for {{$opID}}.
|
||||
type {{$opID}}Output struct {
|
||||
StatusCode *int `location:"statusCode"`
|
||||
// {{$opID}}Output presents output for {{$opID}}.
|
||||
type {{$opID}}Output struct {
|
||||
StatusCode *int `location:"statusCode"`
|
||||
|
||||
RequestID *string `location:"requestID"`
|
||||
{{range $keyStatus, $valueStatus := $operation.Responses -}}
|
||||
{{if eq $valueStatus.Body.Type "string"}}
|
||||
{{if $valueStatus.Body.Description -}}
|
||||
// {{$valueStatus.Body.Description}}
|
||||
{{- end}}
|
||||
Body string `location:"body"`
|
||||
{{else if eq $valueStatus.Body.Type "binary"}}
|
||||
{{if $valueStatus.Body.Description -}}
|
||||
// {{$valueStatus.Body.Description}}
|
||||
{{- end}}
|
||||
Body io.ReadCloser `location:"body"`
|
||||
{{end}}
|
||||
RequestID *string `location:"requestID"`
|
||||
{{range $keyStatus, $valueStatus := $operation.Responses -}}
|
||||
{{if eq $valueStatus.Body.Type "string"}}
|
||||
{{if $valueStatus.Body.Description -}}
|
||||
// {{$valueStatus.Body.Description}}
|
||||
{{- end}}
|
||||
Body string `location:"body"`
|
||||
{{else if eq $valueStatus.Body.Type "binary"}}
|
||||
{{if $valueStatus.Body.Description -}}
|
||||
// {{$valueStatus.Body.Description}}
|
||||
{{- end}}
|
||||
Body io.ReadCloser `location:"body"`
|
||||
{{end}}
|
||||
|
||||
{{if $valueStatus.Elements.Properties | len}}
|
||||
{{$data := $valueStatus.Elements}}
|
||||
{{template "RenderProperties" passThrough $data `location:"elements"` $operation.Name}}
|
||||
{{end}}
|
||||
{{if $valueStatus.Elements.Properties | len}}
|
||||
{{$data := $valueStatus.Elements}}
|
||||
{{template "RenderProperties" passThrough $data `location:"elements"` $operation.Name}}
|
||||
{{end}}
|
||||
|
||||
{{if $valueStatus.Headers.Properties | len}}
|
||||
{{$data := $valueStatus.Headers}}
|
||||
{{template "RenderProperties" passThrough $data `location:"headers"` $operation.Name}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
}
|
||||
{{if $valueStatus.Headers.Properties | len}}
|
||||
{{$data := $valueStatus.Headers}}
|
||||
{{template "RenderProperties" passThrough $data `location:"headers"` $operation.Name}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
{{define "SubServiceInitParams"}}
|
||||
{{- $customizedType := index . 0 -}}
|
||||
{{- $disablePointer := index . 1 -}}
|
||||
{{- $customizedType := index . 0 -}}
|
||||
{{- $disablePointer := index . 1 -}}
|
||||
|
||||
{{- range $_, $property := $customizedType.Properties -}}
|
||||
{{$property.ID | camelCase | lowerFirstWord}}{{" " -}}
|
||||
{{template "PropertyType" passThrough $property $disablePointer}},
|
||||
{{- end -}}
|
||||
{{- range $_, $property := $customizedType.Properties -}}
|
||||
{{$property.ID | camelCase | lowerFirstWord}}{{" " -}}
|
||||
{{template "PropertyType" passThrough $property $disablePointer}},
|
||||
{{- end -}}
|
||||
{{end}}
|
||||
|
||||
{{define "ValidateCustomizedType"}}
|
||||
{{$customizedType := index . 0}}
|
||||
{{$operationName := index . 1}}
|
||||
{{$customizedType := index . 0}}
|
||||
{{$operationName := index . 1}}
|
||||
|
||||
{{range $_, $property := $customizedType.Properties}}
|
||||
{{if or (ne $operationName "Delete Multiple Objects") (ne $property.ID "Content-MD5") -}}
|
||||
{{$isNormalType := or (eq $property.Type "string") (eq $property.Type "integer")}}
|
||||
{{$isContentLength := eq $property.ID "Content-Length"}}
|
||||
{{if and $isNormalType (not $isContentLength) }}
|
||||
{{if $property.IsRequired }}
|
||||
if v.{{$property.ID | camelCase}} == nil {
|
||||
return errors.ParameterRequiredError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParentName: "{{$customizedType.ID | camelCase}}",
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{$parameterName := $property.ID | camelCase | lowerFirstWord}}
|
||||
{{if gt ($property.Enum | len) 0}}
|
||||
if v.{{$property.ID | camelCase}} != nil {
|
||||
{{$parameterName}}ValidValues := []string{
|
||||
{{- $property.Enum | commaConnectedWithQuote -}}
|
||||
}
|
||||
{{$parameterName}}ParameterValue := fmt.Sprint(*v.{{$property.ID | camelCase}})
|
||||
{{range $_, $property := $customizedType.Properties}}
|
||||
{{if or (ne $operationName "Delete Multiple Objects") (ne $property.ID "Content-MD5") -}}
|
||||
{{$isNormalType := or (eq $property.Type "string") (eq $property.Type "integer")}}
|
||||
{{$isContentLength := eq $property.ID "Content-Length"}}
|
||||
{{if and $isNormalType (not $isContentLength) }}
|
||||
{{if $property.IsRequired }}
|
||||
if v.{{$property.ID | camelCase}} == nil {
|
||||
return errors.ParameterRequiredError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParentName: "{{$customizedType.ID | camelCase}}",
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{$parameterName := $property.ID | camelCase | lowerFirstWord}}
|
||||
{{if gt ($property.Enum | len) 0}}
|
||||
if v.{{$property.ID | camelCase}} != nil {
|
||||
{{$parameterName}}ValidValues := []string{
|
||||
{{- $property.Enum | commaConnectedWithQuote -}}
|
||||
}
|
||||
{{$parameterName}}ParameterValue := fmt.Sprint(*v.{{$property.ID | camelCase}})
|
||||
|
||||
{{$parameterName}}IsValid := false
|
||||
for _, value := range {{$parameterName}}ValidValues {
|
||||
if value == {{$parameterName}}ParameterValue {
|
||||
{{$parameterName}}IsValid = true
|
||||
}
|
||||
}
|
||||
{{$parameterName}}IsValid := false
|
||||
for _, value := range {{$parameterName}}ValidValues {
|
||||
if value == {{$parameterName}}ParameterValue {
|
||||
{{$parameterName}}IsValid = true
|
||||
}
|
||||
}
|
||||
|
||||
if !{{$parameterName}}IsValid {
|
||||
return errors.ParameterValueNotAllowedError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParameterValue: {{$parameterName}}ParameterValue,
|
||||
AllowedValues: {{$parameterName}}ValidValues,
|
||||
}
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
if !{{$parameterName}}IsValid {
|
||||
return errors.ParameterValueNotAllowedError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParameterValue: {{$parameterName}}ParameterValue,
|
||||
AllowedValues: {{$parameterName}}ValidValues,
|
||||
}
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{if eq $property.Type "object"}}
|
||||
if v.{{$property.ID | camelCase}} != nil {
|
||||
if err := v.{{$property.ID | camelCase}}.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
{{if $property.IsRequired }}
|
||||
if v.{{$property.ID | camelCase}} == nil {
|
||||
return errors.ParameterRequiredError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParentName: "{{$customizedType.ID | camelCase}}",
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{if eq $property.Type "object"}}
|
||||
if v.{{$property.ID | camelCase}} != nil {
|
||||
if err := v.{{$property.ID | camelCase}}.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
{{if $property.IsRequired }}
|
||||
if v.{{$property.ID | camelCase}} == nil {
|
||||
return errors.ParameterRequiredError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParentName: "{{$customizedType.ID | camelCase}}",
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{if eq $property.Type "array"}}
|
||||
{{if $property.IsRequired}}
|
||||
if len(v.{{$property.ID | camelCase}}) == 0 {
|
||||
return errors.ParameterRequiredError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParentName: "{{$customizedType.ID | camelCase}}",
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{$isNotString := ne $property.ExtraType "string"}}
|
||||
{{$isNotInteger := ne $property.ExtraType "integer"}}
|
||||
{{$isNotTimestamp := ne $property.ExtraType "timestamp"}}
|
||||
{{if and $isNotString $isNotInteger $isNotTimestamp}}
|
||||
if len(v.{{$property.ID | camelCase}}) > 0 {
|
||||
for _, property := range v.{{$property.ID | camelCase}} {
|
||||
if err := property.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{if eq $property.Type "array"}}
|
||||
{{if $property.IsRequired}}
|
||||
if len(v.{{$property.ID | camelCase}}) == 0 {
|
||||
return errors.ParameterRequiredError{
|
||||
ParameterName: "{{$property.ID | camelCase}}",
|
||||
ParentName: "{{$customizedType.ID | camelCase}}",
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{$isNotString := ne $property.ExtraType "string"}}
|
||||
{{$isNotInteger := ne $property.ExtraType "integer"}}
|
||||
{{$isNotTimestamp := ne $property.ExtraType "timestamp"}}
|
||||
{{if and $isNotString $isNotInteger $isNotTimestamp}}
|
||||
if len(v.{{$property.ID | camelCase}}) > 0 {
|
||||
for _, property := range v.{{$property.ID | camelCase}} {
|
||||
if err := property.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
+31
-31
@@ -20,16 +20,16 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"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"
|
||||
"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
|
||||
@@ -40,31 +40,31 @@ var _ time.Time
|
||||
var _ config.Config
|
||||
|
||||
{{if ne $subService.Name "Object"}}
|
||||
// {{$subService.ID | camelCase}} presents {{$subService.ID | snakeCase}}.
|
||||
type {{$subService.ID | camelCase}} struct {
|
||||
Config *config.Config
|
||||
Properties *Properties
|
||||
}
|
||||
// {{$subService.ID | camelCase}} presents {{$subService.ID | snakeCase}}.
|
||||
type {{$subService.ID | camelCase}} struct {
|
||||
Config *config.Config
|
||||
Properties *Properties
|
||||
}
|
||||
|
||||
// {{$subService.ID | camelCase}} initializes a new {{$subService.ID | snakeCase}}.
|
||||
func (s *Service) {{$subService.ID | camelCase}}(
|
||||
{{- template "SubServiceInitParams" passThrough $subService.Properties true -}}
|
||||
) (*{{$subService.ID | camelCase}}, error) {
|
||||
{{- range $_, $property := $subService.Properties.Properties -}}
|
||||
{{if eq $property.ID "zone"}}
|
||||
{{$property.ID}} = strings.ToLower({{$property.ID}})
|
||||
{{end}}
|
||||
{{- end -}}
|
||||
properties := &Properties{
|
||||
{{range $_, $property := $subService.Properties.Properties -}}
|
||||
{{$property.ID | upperFirst}}: &{{$property.ID}},
|
||||
{{end -}}
|
||||
}
|
||||
// {{$subService.ID | camelCase}} initializes a new {{$subService.ID | snakeCase}}.
|
||||
func (s *Service) {{$subService.ID | camelCase}}(
|
||||
{{- template "SubServiceInitParams" passThrough $subService.Properties true -}}
|
||||
) (*{{$subService.ID | camelCase}}, error) {
|
||||
{{- range $_, $property := $subService.Properties.Properties -}}
|
||||
{{if eq $property.ID "zone"}}
|
||||
{{$property.ID}} = strings.ToLower({{$property.ID}})
|
||||
{{end}}
|
||||
{{- end -}}
|
||||
properties := &Properties{
|
||||
{{range $_, $property := $subService.Properties.Properties -}}
|
||||
{{$property.ID | upperFirst}}: &{{$property.ID}},
|
||||
{{end -}}
|
||||
}
|
||||
|
||||
return &{{$subService.ID | camelCase}}{Config: s.Config, Properties: properties}, nil
|
||||
}
|
||||
return &{{$subService.ID | camelCase}}{Config: s.Config, Properties: properties}, nil
|
||||
}
|
||||
{{end}}
|
||||
|
||||
{{range $_, $operation := $subService.Operations}}
|
||||
{{template "RenderOperation" passThrough $subService $operation}}
|
||||
{{template "RenderOperation" passThrough $subService $operation}}
|
||||
{{end}}
|
||||
|
||||
+29
-29
@@ -21,43 +21,43 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/yunify/qingstor-sdk-go/request/errors"
|
||||
"github.com/yunify/qingstor-sdk-go/request/errors"
|
||||
)
|
||||
|
||||
// Properties presents the service properties.
|
||||
type Properties struct {
|
||||
{{- template "RenderProperties" passThrough $service.Properties "" "" -}}
|
||||
{{if $objectSubService -}}
|
||||
{{range $_, $p := $objectSubService.Properties.Properties -}}
|
||||
{{- if $p.Description -}}
|
||||
// {{$p.Description}}
|
||||
{{end -}}
|
||||
{{if $p.Enum -}}
|
||||
// {{camelCase $p.ID}}'s available values: {{commaConnected $p.Enum}}
|
||||
{{end -}}
|
||||
{{$p.ID | camelCase | upperFirst}}{{" " -}}
|
||||
{{template "PropertyType" passThrough $p false}}{{" " -}}
|
||||
`{{template "PropertyTagsDashConnected" $p}}`{{" " -}}
|
||||
{{if $p.IsRequired -}}
|
||||
// Required
|
||||
{{- end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{- template "RenderProperties" passThrough $service.Properties "" "" -}}
|
||||
{{if $objectSubService -}}
|
||||
{{range $_, $p := $objectSubService.Properties.Properties -}}
|
||||
{{- if $p.Description -}}
|
||||
// {{$p.Description}}
|
||||
{{end -}}
|
||||
{{if $p.Enum -}}
|
||||
// {{camelCase $p.ID}}'s available values: {{commaConnected $p.Enum}}
|
||||
{{end -}}
|
||||
{{$p.ID | camelCase | upperFirst}}{{" " -}}
|
||||
{{template "PropertyType" passThrough $p false}}{{" " -}}
|
||||
`{{template "PropertyTagsDashConnected" $p}}`{{" " -}}
|
||||
{{if $p.IsRequired -}}
|
||||
// Required
|
||||
{{- end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
}
|
||||
|
||||
{{range $_, $customizedType := $customizedTypes}}
|
||||
// {{$customizedType.ID | camelCase}}Type presents {{$customizedType.ID | camelCase}}.
|
||||
type {{$customizedType.ID | camelCase}}Type struct {
|
||||
{{template "RenderProperties" passThrough $customizedType "" ""}}
|
||||
}
|
||||
// {{$customizedType.ID | camelCase}}Type presents {{$customizedType.ID | camelCase}}.
|
||||
type {{$customizedType.ID | camelCase}}Type struct {
|
||||
{{template "RenderProperties" passThrough $customizedType "" ""}}
|
||||
}
|
||||
|
||||
// Validate validates the {{$customizedType.ID | camelCase}}.
|
||||
func (v *{{$customizedType.ID | camelCase}}Type) Validate() error {
|
||||
{{template "ValidateCustomizedType" passThrough $customizedType ""}}
|
||||
// Validate validates the {{$customizedType.ID | camelCase}}.
|
||||
func (v *{{$customizedType.ID | camelCase}}Type) Validate() error {
|
||||
{{template "ValidateCustomizedType" passThrough $customizedType ""}}
|
||||
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user