github.com/go-swagger/go-swagger@v0.31.0/examples/cli/client/a_to_do_list_application_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  	"github.com/go-openapi/strfmt"
    12  
    13  	"github.com/go-swagger/go-swagger/examples/cli/client/operations"
    14  	"github.com/go-swagger/go-swagger/examples/cli/client/todos"
    15  )
    16  
    17  // Default a to do list application 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 = "/"
    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 a to do list application HTTP client.
    33  func NewHTTPClient(formats strfmt.Registry) *AToDoListApplication {
    34  	return NewHTTPClientWithConfig(formats, nil)
    35  }
    36  
    37  // NewHTTPClientWithConfig creates a new a to do list application HTTP client,
    38  // using a customizable transport config.
    39  func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *AToDoListApplication {
    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 a to do list application client
    51  func New(transport runtime.ClientTransport, formats strfmt.Registry) *AToDoListApplication {
    52  	// ensure nullable parameters have default
    53  	if formats == nil {
    54  		formats = strfmt.Default
    55  	}
    56  
    57  	cli := new(AToDoListApplication)
    58  	cli.Transport = transport
    59  	cli.Operations = operations.New(transport, formats)
    60  	cli.Todos = todos.New(transport, formats)
    61  	return cli
    62  }
    63  
    64  // DefaultTransportConfig creates a TransportConfig with the
    65  // default settings taken from the meta section of the spec file.
    66  func DefaultTransportConfig() *TransportConfig {
    67  	return &TransportConfig{
    68  		Host:     DefaultHost,
    69  		BasePath: DefaultBasePath,
    70  		Schemes:  DefaultSchemes,
    71  	}
    72  }
    73  
    74  // TransportConfig contains the transport related info,
    75  // found in the meta section of the spec file.
    76  type TransportConfig struct {
    77  	Host     string
    78  	BasePath string
    79  	Schemes  []string
    80  }
    81  
    82  // WithHost overrides the default host,
    83  // provided by the meta section of the spec file.
    84  func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
    85  	cfg.Host = host
    86  	return cfg
    87  }
    88  
    89  // WithBasePath overrides the default basePath,
    90  // provided by the meta section of the spec file.
    91  func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
    92  	cfg.BasePath = basePath
    93  	return cfg
    94  }
    95  
    96  // WithSchemes overrides the default schemes,
    97  // provided by the meta section of the spec file.
    98  func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
    99  	cfg.Schemes = schemes
   100  	return cfg
   101  }
   102  
   103  // AToDoListApplication is a client for a to do list application
   104  type AToDoListApplication struct {
   105  	Operations operations.ClientService
   106  
   107  	Todos todos.ClientService
   108  
   109  	Transport runtime.ClientTransport
   110  }
   111  
   112  // SetTransport changes the transport on the client and all its subresources
   113  func (c *AToDoListApplication) SetTransport(transport runtime.ClientTransport) {
   114  	c.Transport = transport
   115  	c.Operations.SetTransport(transport)
   116  	c.Todos.SetTransport(transport)
   117  }