github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/examples/todo-list/client/todo_list_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/todo-list/client/todos" 14 ) 15 16 // Default todo list HTTP client. 17 var Default = NewHTTPClient(nil) 18 19 const ( 20 // DefaultHost is the default Host 21 // found in Meta (info) section of spec file 22 DefaultHost string = "localhost" 23 // DefaultBasePath is the default BasePath 24 // found in Meta (info) section of spec file 25 DefaultBasePath string = "/" 26 ) 27 28 // DefaultSchemes are the default schemes found in Meta (info) section of spec file 29 var DefaultSchemes = []string{"http", "https"} 30 31 // NewHTTPClient creates a new todo list HTTP client. 32 func NewHTTPClient(formats strfmt.Registry) *TodoList { 33 return NewHTTPClientWithConfig(formats, nil) 34 } 35 36 // NewHTTPClientWithConfig creates a new todo list HTTP client, 37 // using a customizable transport config. 38 func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *TodoList { 39 // ensure nullable parameters have default 40 if cfg == nil { 41 cfg = DefaultTransportConfig() 42 } 43 44 // create transport and client 45 transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes) 46 return New(transport, formats) 47 } 48 49 // New creates a new todo list client 50 func New(transport runtime.ClientTransport, formats strfmt.Registry) *TodoList { 51 // ensure nullable parameters have default 52 if formats == nil { 53 formats = strfmt.Default 54 } 55 56 cli := new(TodoList) 57 cli.Transport = transport 58 cli.Todos = todos.New(transport, formats) 59 return cli 60 } 61 62 // DefaultTransportConfig creates a TransportConfig with the 63 // default settings taken from the meta section of the spec file. 64 func DefaultTransportConfig() *TransportConfig { 65 return &TransportConfig{ 66 Host: DefaultHost, 67 BasePath: DefaultBasePath, 68 Schemes: DefaultSchemes, 69 } 70 } 71 72 // TransportConfig contains the transport related info, 73 // found in the meta section of the spec file. 74 type TransportConfig struct { 75 Host string 76 BasePath string 77 Schemes []string 78 } 79 80 // WithHost overrides the default host, 81 // provided by the meta section of the spec file. 82 func (cfg *TransportConfig) WithHost(host string) *TransportConfig { 83 cfg.Host = host 84 return cfg 85 } 86 87 // WithBasePath overrides the default basePath, 88 // provided by the meta section of the spec file. 89 func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig { 90 cfg.BasePath = basePath 91 return cfg 92 } 93 94 // WithSchemes overrides the default schemes, 95 // provided by the meta section of the spec file. 96 func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig { 97 cfg.Schemes = schemes 98 return cfg 99 } 100 101 // TodoList is a client for todo list 102 type TodoList struct { 103 Todos todos.ClientService 104 105 Transport runtime.ClientTransport 106 } 107 108 // SetTransport changes the transport on the client and all its subresources 109 func (c *TodoList) SetTransport(transport runtime.ClientTransport) { 110 c.Transport = transport 111 c.Todos.SetTransport(transport) 112 }