github.com/kaisawind/go-swagger@v0.19.0/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    // {{ pascalize .Name }} {{ if .Summary }}{{ pluralizeFirstWord (humanize .Summary) }}{{ if .Description }}
    33    // {{ blockcomment .Description }}{{ end }}{{ else if .Description}}{{ blockcomment .Description }}{{ else }}{{ humanize .Name }} API{{ end }}
    34    {{ 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 }}
    35  {{ end -}}
    36  }
    37  
    38  // New creates a new {{ humanize .Name }} API client.
    39  func New(transport runtime.ClientTransport, formats strfmt.Registry, authInfo runtime.ClientAuthInfoWriter) *Client {
    40    return &Client{
    41      transport: transport,
    42      formats: formats,
    43      authInfo: authInfo,
    44    }
    45  }
    46  
    47  /*
    48  Client {{ if .Summary }}{{ .Summary }}{{ if .Description }}
    49  
    50  {{ blockcomment .Description }}{{ end }}{{ else if .Description}}{{ blockcomment .Description }}{{ else }}for {{ humanize .Name }} API{{ end }}
    51  */
    52  type Client struct {
    53    transport runtime.ClientTransport
    54    formats strfmt.Registry
    55    authInfo runtime.ClientAuthInfoWriter
    56  }
    57  
    58  {{ range .Operations -}}
    59  /*
    60  {{ pascalize .Name }} {{ if .Summary }}{{ pluralizeFirstWord (humanize .Summary) }}{{ if .Description }}
    61  
    62  {{ blockcomment .Description }}{{ end }}{{ else if .Description}}{{ blockcomment .Description }}{{ else }}{{ humanize .Name }} API{{ end }}
    63  */
    64  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 }} {
    65    {{ $length := len .SuccessResponses }}
    66    {{ if .SuccessResponse }}result{{else}}_{{ end }}, err := a.transport.Submit(&runtime.ClientOperation{
    67      ID: {{ printf "%q" .Name }},
    68      Method: {{ printf "%q" .Method }},
    69      PathPattern: {{ printf "%q" .Path }},
    70      ProducesMediaTypes: {{ printf "%#v" .ProducesMediaTypes }},
    71      ConsumesMediaTypes: {{ printf "%#v" .ConsumesMediaTypes }},
    72      Schemes: {{ printf "%#v" .Schemes }},
    73      Params: params,
    74      Reader: &{{ pascalize .Name }}Reader{formats: a.formats{{ if .HasStreamingResponse }}, writer: writer{{ end }}},
    75      {{ if .Authorized -}}
    76      AuthInfo: a.authInfo,
    77      {{ end -}}
    78      Context: ctx,
    79      Client:  params.HTTPClient,
    80    })
    81    if err != nil {
    82      return {{ if .SuccessResponse }}{{ padSurround "nil" "nil" 0 $length }}, {{ end }}err
    83    }
    84    {{ if .SuccessResponse }}{{ if eq $length 1 }}return result.(*{{ pascalize .SuccessResponse.Name }}), nil{{ else }}switch value := result.(type) { {{ range $i, $v := .SuccessResponses }}
    85      case *{{ pascalize $v.Name }}:
    86        return {{ padSurround "value" "nil" $i $length }}, nil{{ end }} }
    87    return {{ padSurround "nil" "nil" 0 $length }}, nil{{ end }}
    88    {{ else }}return nil{{ end }}
    89  
    90  }
    91  {{ end }}