github.com/johnlanni/go-swagger@v0.19.0/examples/authentication/client/auth_sample_client.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package client
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"github.com/go-openapi/runtime"
    10  	httptransport "github.com/go-openapi/runtime/client"
    11  
    12  	strfmt "github.com/go-openapi/strfmt"
    13  
    14  	"github.com/go-swagger/go-swagger/examples/authentication/client/customers"
    15  )
    16  
    17  // Default auth sample HTTP client.
    18  var Default = NewHTTPClient(nil)
    19  
    20  const (
    21  	// DefaultHost is the default Host
    22  	// found in Meta (info) section of spec file
    23  	DefaultHost string = "localhost"
    24  	// DefaultBasePath is the default BasePath
    25  	// found in Meta (info) section of spec file
    26  	DefaultBasePath string = "/api"
    27  )
    28  
    29  // DefaultSchemes are the default schemes found in Meta (info) section of spec file
    30  var DefaultSchemes = []string{"http"}
    31  
    32  // NewHTTPClient creates a new auth sample HTTP client.
    33  func NewHTTPClient(formats strfmt.Registry) *AuthSample {
    34  	return NewHTTPClientWithConfig(formats, nil)
    35  }
    36  
    37  // NewHTTPClientWithConfig creates a new auth sample HTTP client,
    38  // using a customizable transport config.
    39  func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *AuthSample {
    40  	// ensure nullable parameters have default
    41  	if cfg == nil {
    42  		cfg = DefaultTransportConfig()
    43  	}
    44  
    45  	// create transport and client
    46  	transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
    47  	return New(transport, formats)
    48  }
    49  
    50  // New creates a new auth sample client
    51  func New(transport runtime.ClientTransport, formats strfmt.Registry) *AuthSample {
    52  	// ensure nullable parameters have default
    53  	if formats == nil {
    54  		formats = strfmt.Default
    55  	}
    56  
    57  	cli := new(AuthSample)
    58  	cli.Transport = transport
    59  
    60  	cli.Customers = customers.New(transport, formats)
    61  
    62  	return cli
    63  }
    64  
    65  // DefaultTransportConfig creates a TransportConfig with the
    66  // default settings taken from the meta section of the spec file.
    67  func DefaultTransportConfig() *TransportConfig {
    68  	return &TransportConfig{
    69  		Host:     DefaultHost,
    70  		BasePath: DefaultBasePath,
    71  		Schemes:  DefaultSchemes,
    72  	}
    73  }
    74  
    75  // TransportConfig contains the transport related info,
    76  // found in the meta section of the spec file.
    77  type TransportConfig struct {
    78  	Host     string
    79  	BasePath string
    80  	Schemes  []string
    81  }
    82  
    83  // WithHost overrides the default host,
    84  // provided by the meta section of the spec file.
    85  func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
    86  	cfg.Host = host
    87  	return cfg
    88  }
    89  
    90  // WithBasePath overrides the default basePath,
    91  // provided by the meta section of the spec file.
    92  func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
    93  	cfg.BasePath = basePath
    94  	return cfg
    95  }
    96  
    97  // WithSchemes overrides the default schemes,
    98  // provided by the meta section of the spec file.
    99  func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
   100  	cfg.Schemes = schemes
   101  	return cfg
   102  }
   103  
   104  // AuthSample is a client for auth sample
   105  type AuthSample struct {
   106  	Customers *customers.Client
   107  
   108  	Transport runtime.ClientTransport
   109  }
   110  
   111  // SetTransport changes the transport on the client and all its subresources
   112  func (c *AuthSample) SetTransport(transport runtime.ClientTransport) {
   113  	c.Transport = transport
   114  
   115  	c.Customers.SetTransport(transport)
   116  
   117  }