github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/examples/file-server/client/file_upload_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/file-server/client/uploads" 14 ) 15 16 // Default file upload 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"} 30 31 // NewHTTPClient creates a new file upload HTTP client. 32 func NewHTTPClient(formats strfmt.Registry) *FileUpload { 33 return NewHTTPClientWithConfig(formats, nil) 34 } 35 36 // NewHTTPClientWithConfig creates a new file upload HTTP client, 37 // using a customizable transport config. 38 func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *FileUpload { 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 file upload client 50 func New(transport runtime.ClientTransport, formats strfmt.Registry) *FileUpload { 51 // ensure nullable parameters have default 52 if formats == nil { 53 formats = strfmt.Default 54 } 55 56 cli := new(FileUpload) 57 cli.Transport = transport 58 cli.Uploads = uploads.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 // FileUpload is a client for file upload 102 type FileUpload struct { 103 Uploads uploads.ClientService 104 105 Transport runtime.ClientTransport 106 } 107 108 // SetTransport changes the transport on the client and all its subresources 109 func (c *FileUpload) SetTransport(transport runtime.ClientTransport) { 110 c.Transport = transport 111 c.Uploads.SetTransport(transport) 112 }