github.com/emreu/go-swagger@v0.22.1/generator/templates/contrib/stratoscale/client/client.gotmpl (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 4 {{ if .Copyright -}}// {{ comment .Copyright -}}{{ end }} 5 6 7 package {{ .Name }} 8 9 // This file was generated by the swagger tool. 10 // Editing this file might prove futile when you re-run the swagger generate command 11 12 import ( 13 "net/http" 14 "github.com/go-openapi/errors" 15 "github.com/go-openapi/swag" 16 "github.com/go-openapi/runtime" 17 "github.com/go-openapi/validate" 18 19 strfmt "github.com/go-openapi/strfmt" 20 21 {{ range .DefaultImports }}{{ printf "%q" .}} 22 {{ end }} 23 {{ range $key, $value := .Imports }}{{ $key }} {{ printf "%q" $value }} 24 {{ end }} 25 ) 26 27 //go:generate mockery -name API -inpkg 28 29 // API is the interface of the {{ humanize .Name }} client 30 type API interface { 31 {{ range .Operations -}} 32 /* 33 {{ pascalize .Name }} {{ if .Summary }}{{ pluralizeFirstWord (humanize .Summary) }}{{ if .Description }} 34 35 {{ blockcomment .Description }}{{ end }}{{ else if .Description}}{{ blockcomment .Description }}{{ else }}{{ humanize .Name }} API{{ end -}} 36 */ 37 {{ pascalize .Name }}(ctx context.Context, params *{{ pascalize .Name }}Params{{ if .HasStreamingResponse }}, writer io.Writer{{ end }}) {{ if .SuccessResponse }}({{ range .SuccessResponses }}*{{ pascalize .Name }}, {{ end }}{{ end }}error{{ if .SuccessResponse }}){{ end }} 38 {{ end -}} 39 } 40 41 // New creates a new {{ humanize .Name }} API client. 42 func New(transport runtime.ClientTransport, formats strfmt.Registry, authInfo runtime.ClientAuthInfoWriter) *Client { 43 return &Client{ 44 transport: transport, 45 formats: formats, 46 authInfo: authInfo, 47 } 48 } 49 50 /* 51 Client {{ if .Summary }}{{ .Summary }}{{ if .Description }} 52 53 {{ blockcomment .Description }}{{ end }}{{ else if .Description}}{{ blockcomment .Description }}{{ else }}for {{ humanize .Name }} API{{ end }} 54 */ 55 type Client struct { 56 transport runtime.ClientTransport 57 formats strfmt.Registry 58 authInfo runtime.ClientAuthInfoWriter 59 } 60 61 {{ range .Operations -}} 62 /* 63 {{ pascalize .Name }} {{ if .Summary }}{{ pluralizeFirstWord (humanize .Summary) }}{{ if .Description }} 64 65 {{ blockcomment .Description }}{{ end }}{{ else if .Description}}{{ blockcomment .Description }}{{ else }}{{ humanize .Name }} API{{ end }} 66 */ 67 func (a *Client) {{ pascalize .Name }}(ctx context.Context, params *{{ pascalize .Name }}Params{{ if .HasStreamingResponse }}, writer io.Writer{{ end }}) {{ if .SuccessResponse }}({{ range .SuccessResponses }}*{{ pascalize .Name }}, {{ end }}{{ end }}error{{ if .SuccessResponse }}){{ end }} { 68 {{ $length := len .SuccessResponses }} 69 {{ if .SuccessResponse }}result{{else}}_{{ end }}, err := a.transport.Submit(&runtime.ClientOperation{ 70 ID: {{ printf "%q" .Name }}, 71 Method: {{ printf "%q" .Method }}, 72 PathPattern: {{ printf "%q" .Path }}, 73 ProducesMediaTypes: {{ printf "%#v" .ProducesMediaTypes }}, 74 ConsumesMediaTypes: {{ printf "%#v" .ConsumesMediaTypes }}, 75 Schemes: {{ printf "%#v" .Schemes }}, 76 Params: params, 77 Reader: &{{ pascalize .Name }}Reader{formats: a.formats{{ if .HasStreamingResponse }}, writer: writer{{ end }}}, 78 {{ if .Authorized -}} 79 AuthInfo: a.authInfo, 80 {{ end -}} 81 Context: ctx, 82 Client: params.HTTPClient, 83 }) 84 if err != nil { 85 return {{ if .SuccessResponse }}{{ padSurround "nil" "nil" 0 $length }}, {{ end }}err 86 } 87 {{ if .SuccessResponse }}{{ if eq $length 1 }}return result.(*{{ pascalize .SuccessResponse.Name }}), nil{{ else }}switch value := result.(type) { {{ range $i, $v := .SuccessResponses }} 88 case *{{ pascalize $v.Name }}: 89 return {{ padSurround "value" "nil" $i $length }}, nil{{ end }} } 90 return {{ padSurround "nil" "nil" 0 $length }}, nil{{ end }} 91 {{ else }}return nil{{ end }} 92 93 } 94 {{ end }}