github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/authentication/client/customers/customers_client.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package customers 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 14 // New creates a new customers API client. 15 func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService { 16 return &Client{transport: transport, formats: formats} 17 } 18 19 // New creates a new customers API client with basic auth credentials. 20 // It takes the following parameters: 21 // - host: http host (github.com). 22 // - basePath: any base path for the API client ("/v1", "/v3"). 23 // - scheme: http scheme ("http", "https"). 24 // - user: user for basic authentication header. 25 // - password: password for basic authentication header. 26 func NewClientWithBasicAuth(host, basePath, scheme, user, password string) ClientService { 27 transport := httptransport.New(host, basePath, []string{scheme}) 28 transport.DefaultAuthentication = httptransport.BasicAuth(user, password) 29 return &Client{transport: transport, formats: strfmt.Default} 30 } 31 32 // New creates a new customers API client with a bearer token for authentication. 33 // It takes the following parameters: 34 // - host: http host (github.com). 35 // - basePath: any base path for the API client ("/v1", "/v3"). 36 // - scheme: http scheme ("http", "https"). 37 // - bearerToken: bearer token for Bearer authentication header. 38 func NewClientWithBearerToken(host, basePath, scheme, bearerToken string) ClientService { 39 transport := httptransport.New(host, basePath, []string{scheme}) 40 transport.DefaultAuthentication = httptransport.BearerToken(bearerToken) 41 return &Client{transport: transport, formats: strfmt.Default} 42 } 43 44 /* 45 Client for customers API 46 */ 47 type Client struct { 48 transport runtime.ClientTransport 49 formats strfmt.Registry 50 } 51 52 // ClientOption is the option for Client methods 53 type ClientOption func(*runtime.ClientOperation) 54 55 // ClientService is the interface for Client methods 56 type ClientService interface { 57 Create(params *CreateParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateCreated, error) 58 59 GetID(params *GetIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetIDOK, error) 60 61 SetTransport(transport runtime.ClientTransport) 62 } 63 64 /* 65 Create creates a new customer to track 66 */ 67 func (a *Client) Create(params *CreateParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateCreated, error) { 68 // TODO: Validate the params before sending 69 if params == nil { 70 params = NewCreateParams() 71 } 72 op := &runtime.ClientOperation{ 73 ID: "create", 74 Method: "POST", 75 PathPattern: "/customers", 76 ProducesMediaTypes: []string{"application/keyauth.api.v1+json"}, 77 ConsumesMediaTypes: []string{"application/keyauth.api.v1+json"}, 78 Schemes: []string{"http"}, 79 Params: params, 80 Reader: &CreateReader{formats: a.formats}, 81 AuthInfo: authInfo, 82 Context: params.Context, 83 Client: params.HTTPClient, 84 } 85 for _, opt := range opts { 86 opt(op) 87 } 88 89 result, err := a.transport.Submit(op) 90 if err != nil { 91 return nil, err 92 } 93 success, ok := result.(*CreateCreated) 94 if ok { 95 return success, nil 96 } 97 // unexpected success response 98 unexpectedSuccess := result.(*CreateDefault) 99 return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 100 } 101 102 /* 103 GetID gets a customer Id given an s s n 104 */ 105 func (a *Client) GetID(params *GetIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetIDOK, error) { 106 // TODO: Validate the params before sending 107 if params == nil { 108 params = NewGetIDParams() 109 } 110 op := &runtime.ClientOperation{ 111 ID: "getId", 112 Method: "GET", 113 PathPattern: "/customers", 114 ProducesMediaTypes: []string{"application/keyauth.api.v1+json"}, 115 ConsumesMediaTypes: []string{"application/keyauth.api.v1+json"}, 116 Schemes: []string{"http"}, 117 Params: params, 118 Reader: &GetIDReader{formats: a.formats}, 119 AuthInfo: authInfo, 120 Context: params.Context, 121 Client: params.HTTPClient, 122 } 123 for _, opt := range opts { 124 opt(op) 125 } 126 127 result, err := a.transport.Submit(op) 128 if err != nil { 129 return nil, err 130 } 131 success, ok := result.(*GetIDOK) 132 if ok { 133 return success, nil 134 } 135 // unexpected success response 136 unexpectedSuccess := result.(*GetIDDefault) 137 return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 138 } 139 140 // SetTransport changes the transport on the client 141 func (a *Client) SetTransport(transport runtime.ClientTransport) { 142 a.transport = transport 143 }