github.com/go-swagger/go-swagger@v0.31.0/examples/cli/client/todos/todos_client.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package todos 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 todos 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 todos 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 todos 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 todos API 46 */ 47 type Client struct { 48 transport runtime.ClientTransport 49 formats strfmt.Registry 50 } 51 52 // ClientOption may be used to customize the behavior of Client methods. 53 type ClientOption func(*runtime.ClientOperation) 54 55 // This client is generated with a few options you might find useful for your swagger spec. 56 // 57 // Feel free to add you own set of options. 58 59 // WithContentType allows the client to force the Content-Type header 60 // to negotiate a specific Consumer from the server. 61 // 62 // You may use this option to set arbitrary extensions to your MIME media type. 63 func WithContentType(mime string) ClientOption { 64 return func(r *runtime.ClientOperation) { 65 r.ConsumesMediaTypes = []string{mime} 66 } 67 } 68 69 // WithContentTypeApplicationIoGoswaggerExamplesTodoListV1JSON sets the Content-Type header to "application/io.goswagger.examples.todo-list.v1+json". 70 func WithContentTypeApplicationIoGoswaggerExamplesTodoListV1JSON(r *runtime.ClientOperation) { 71 r.ConsumesMediaTypes = []string{"application/io.goswagger.examples.todo-list.v1+json"} 72 } 73 74 // WithContentTypeApplicationJSON sets the Content-Type header to "application/json". 75 func WithContentTypeApplicationJSON(r *runtime.ClientOperation) { 76 r.ConsumesMediaTypes = []string{"application/json"} 77 } 78 79 // WithAccept allows the client to force the Accept header 80 // to negotiate a specific Producer from the server. 81 // 82 // You may use this option to set arbitrary extensions to your MIME media type. 83 func WithAccept(mime string) ClientOption { 84 return func(r *runtime.ClientOperation) { 85 r.ProducesMediaTypes = []string{mime} 86 } 87 } 88 89 // WithAcceptApplicationIoGoswaggerExamplesTodoListV1JSON sets the Accept header to "application/io.goswagger.examples.todo-list.v1+json". 90 func WithAcceptApplicationIoGoswaggerExamplesTodoListV1JSON(r *runtime.ClientOperation) { 91 r.ProducesMediaTypes = []string{"application/io.goswagger.examples.todo-list.v1+json"} 92 } 93 94 // WithAcceptApplicationJSON sets the Accept header to "application/json". 95 func WithAcceptApplicationJSON(r *runtime.ClientOperation) { 96 r.ProducesMediaTypes = []string{"application/json"} 97 } 98 99 // ClientService is the interface for Client methods 100 type ClientService interface { 101 AddOne(params *AddOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*AddOneCreated, error) 102 103 DestroyOne(params *DestroyOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DestroyOneNoContent, error) 104 105 FindTodos(params *FindTodosParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*FindTodosOK, error) 106 107 UpdateOne(params *UpdateOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateOneOK, error) 108 109 SetTransport(transport runtime.ClientTransport) 110 } 111 112 /* 113 AddOne add one API 114 */ 115 func (a *Client) AddOne(params *AddOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*AddOneCreated, error) { 116 // TODO: Validate the params before sending 117 if params == nil { 118 params = NewAddOneParams() 119 } 120 op := &runtime.ClientOperation{ 121 ID: "addOne", 122 Method: "POST", 123 PathPattern: "/", 124 ProducesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 125 ConsumesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 126 Schemes: []string{"http"}, 127 Params: params, 128 Reader: &AddOneReader{formats: a.formats}, 129 AuthInfo: authInfo, 130 Context: params.Context, 131 Client: params.HTTPClient, 132 } 133 for _, opt := range opts { 134 opt(op) 135 } 136 137 result, err := a.transport.Submit(op) 138 if err != nil { 139 return nil, err 140 } 141 success, ok := result.(*AddOneCreated) 142 if ok { 143 return success, nil 144 } 145 // unexpected success response 146 unexpectedSuccess := result.(*AddOneDefault) 147 return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 148 } 149 150 /* 151 DestroyOne destroy one API 152 */ 153 func (a *Client) DestroyOne(params *DestroyOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DestroyOneNoContent, error) { 154 // TODO: Validate the params before sending 155 if params == nil { 156 params = NewDestroyOneParams() 157 } 158 op := &runtime.ClientOperation{ 159 ID: "destroyOne", 160 Method: "DELETE", 161 PathPattern: "/{id}", 162 ProducesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 163 ConsumesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 164 Schemes: []string{"http"}, 165 Params: params, 166 Reader: &DestroyOneReader{formats: a.formats}, 167 AuthInfo: authInfo, 168 Context: params.Context, 169 Client: params.HTTPClient, 170 } 171 for _, opt := range opts { 172 opt(op) 173 } 174 175 result, err := a.transport.Submit(op) 176 if err != nil { 177 return nil, err 178 } 179 success, ok := result.(*DestroyOneNoContent) 180 if ok { 181 return success, nil 182 } 183 // unexpected success response 184 unexpectedSuccess := result.(*DestroyOneDefault) 185 return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 186 } 187 188 /* 189 FindTodos find todos API 190 */ 191 func (a *Client) FindTodos(params *FindTodosParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*FindTodosOK, error) { 192 // TODO: Validate the params before sending 193 if params == nil { 194 params = NewFindTodosParams() 195 } 196 op := &runtime.ClientOperation{ 197 ID: "findTodos", 198 Method: "GET", 199 PathPattern: "/", 200 ProducesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 201 ConsumesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 202 Schemes: []string{"http"}, 203 Params: params, 204 Reader: &FindTodosReader{formats: a.formats}, 205 AuthInfo: authInfo, 206 Context: params.Context, 207 Client: params.HTTPClient, 208 } 209 for _, opt := range opts { 210 opt(op) 211 } 212 213 result, err := a.transport.Submit(op) 214 if err != nil { 215 return nil, err 216 } 217 success, ok := result.(*FindTodosOK) 218 if ok { 219 return success, nil 220 } 221 // unexpected success response 222 unexpectedSuccess := result.(*FindTodosDefault) 223 return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 224 } 225 226 /* 227 UpdateOne update one API 228 */ 229 func (a *Client) UpdateOne(params *UpdateOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateOneOK, error) { 230 // TODO: Validate the params before sending 231 if params == nil { 232 params = NewUpdateOneParams() 233 } 234 op := &runtime.ClientOperation{ 235 ID: "updateOne", 236 Method: "PUT", 237 PathPattern: "/{id}", 238 ProducesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 239 ConsumesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 240 Schemes: []string{"http"}, 241 Params: params, 242 Reader: &UpdateOneReader{formats: a.formats}, 243 AuthInfo: authInfo, 244 Context: params.Context, 245 Client: params.HTTPClient, 246 } 247 for _, opt := range opts { 248 opt(op) 249 } 250 251 result, err := a.transport.Submit(op) 252 if err != nil { 253 return nil, err 254 } 255 success, ok := result.(*UpdateOneOK) 256 if ok { 257 return success, nil 258 } 259 // unexpected success response 260 unexpectedSuccess := result.(*UpdateOneDefault) 261 return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 262 } 263 264 // SetTransport changes the transport on the client 265 func (a *Client) SetTransport(transport runtime.ClientTransport) { 266 a.transport = transport 267 }