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