github.com/kaisawind/go-swagger@v0.19.0/generator/templates/client/facade.gotmpl (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  
     4  {{ if .Copyright -}}// {{ comment .Copyright -}}{{ end }}
     5  
     6  
     7  package {{ .Package }}
     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  
    13  import (
    14    "net/http"
    15    "github.com/go-openapi/runtime"
    16    httptransport "github.com/go-openapi/runtime/client"
    17    "github.com/go-openapi/swag"
    18    "github.com/go-openapi/spec"
    19    "github.com/go-openapi/errors"
    20    "github.com/go-openapi/runtime"
    21  
    22    strfmt "github.com/go-openapi/strfmt"
    23  
    24    {{ range .DefaultImports }}{{ printf "%q" .}}
    25    {{ end }}
    26    {{ range $key, $value := .Imports }}{{ $key }} {{ printf "%q" $value }}
    27    {{ end }}
    28  )
    29  
    30  // Default {{ humanize .Name }} HTTP client.
    31  var Default = NewHTTPClient(nil)
    32  
    33  const (
    34      // DefaultHost is the default Host
    35      // found in Meta (info) section of spec file
    36      DefaultHost string = {{ printf "%#v" .Host }}
    37      // DefaultBasePath is the default BasePath
    38      // found in Meta (info) section of spec file
    39      DefaultBasePath string = {{ printf "%#v" .BasePath }}
    40  )
    41  
    42  // DefaultSchemes are the default schemes found in Meta (info) section of spec file
    43  var DefaultSchemes = {{ printf "%#v" .Schemes }}
    44  
    45  // NewHTTPClient creates a new {{ humanize .Name }} HTTP client.
    46  func NewHTTPClient(formats strfmt.Registry) *{{ pascalize .Name }} {
    47    return NewHTTPClientWithConfig(formats, nil)
    48  }
    49  
    50  // NewHTTPClientWithConfig creates a new {{ humanize .Name }} HTTP client,
    51  // using a customizable transport config.
    52  func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *{{ pascalize .Name }} {
    53    // ensure nullable parameters have default
    54    if cfg == nil {
    55      cfg = DefaultTransportConfig()
    56    }
    57  
    58    // create transport and client
    59    transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
    60    return New(transport, formats)
    61  }
    62  
    63  // New creates a new {{ humanize .Name }} client
    64  func New(transport runtime.ClientTransport, formats strfmt.Registry) *{{ pascalize .Name }} {
    65    // ensure nullable parameters have default
    66    if formats == nil {
    67      formats = strfmt.Default
    68    }
    69  
    70    cli := new({{ pascalize .Name }})
    71    cli.Transport = transport
    72    {{ range .OperationGroups }}
    73    cli.{{ pascalize .Name }} = {{ .Name }}.New(transport, formats)
    74    {{ end }}
    75    return cli
    76  }
    77  
    78  // DefaultTransportConfig creates a TransportConfig with the
    79  // default settings taken from the meta section of the spec file.
    80  func DefaultTransportConfig() *TransportConfig {
    81      return &TransportConfig {
    82          Host: DefaultHost,
    83          BasePath: DefaultBasePath,
    84          Schemes: DefaultSchemes,
    85      }
    86  }
    87  
    88  // TransportConfig contains the transport related info,
    89  // found in the meta section of the spec file.
    90  type TransportConfig struct {
    91      Host string
    92      BasePath string
    93      Schemes []string
    94  }
    95  
    96  // WithHost overrides the default host,
    97  // provided by the meta section of the spec file.
    98  func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
    99      cfg.Host = host
   100      return cfg
   101  }
   102  
   103  // WithBasePath overrides the default basePath,
   104  // provided by the meta section of the spec file.
   105  func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
   106      cfg.BasePath = basePath
   107      return cfg
   108  }
   109  
   110  // WithSchemes overrides the default schemes,
   111  // provided by the meta section of the spec file.
   112  func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
   113      cfg.Schemes = schemes
   114      return cfg
   115  }
   116  
   117  // {{ pascalize .Name }} is a client for {{ humanize .Name }}
   118  type {{ pascalize .Name }} struct {
   119    {{ range .OperationGroups }}
   120    {{ pascalize .Name }} *{{ .Name }}.Client
   121    {{ end }}
   122    Transport runtime.ClientTransport
   123  }
   124  
   125  
   126  // SetTransport changes the transport on the client and all its subresources
   127  func (c *{{pascalize .Name}}) SetTransport(transport runtime.ClientTransport) {
   128    c.Transport = transport
   129    {{ range .OperationGroups }}
   130    c.{{ pascalize .Name }}.SetTransport(transport)
   131    {{ end }}
   132  }