github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/todo-list/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 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  	AddOne(params *AddOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*AddOneCreated, error)
    58  
    59  	DestroyOne(params *DestroyOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DestroyOneNoContent, error)
    60  
    61  	Find(params *FindParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*FindOK, error)
    62  
    63  	UpdateOne(params *UpdateOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateOneOK, error)
    64  
    65  	SetTransport(transport runtime.ClientTransport)
    66  }
    67  
    68  /*
    69  AddOne add one API
    70  */
    71  func (a *Client) AddOne(params *AddOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*AddOneCreated, error) {
    72  	// TODO: Validate the params before sending
    73  	if params == nil {
    74  		params = NewAddOneParams()
    75  	}
    76  	op := &runtime.ClientOperation{
    77  		ID:                 "addOne",
    78  		Method:             "POST",
    79  		PathPattern:        "/",
    80  		ProducesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
    81  		ConsumesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
    82  		Schemes:            []string{"http", "https"},
    83  		Params:             params,
    84  		Reader:             &AddOneReader{formats: a.formats},
    85  		AuthInfo:           authInfo,
    86  		Context:            params.Context,
    87  		Client:             params.HTTPClient,
    88  	}
    89  	for _, opt := range opts {
    90  		opt(op)
    91  	}
    92  
    93  	result, err := a.transport.Submit(op)
    94  	if err != nil {
    95  		return nil, err
    96  	}
    97  	success, ok := result.(*AddOneCreated)
    98  	if ok {
    99  		return success, nil
   100  	}
   101  	// unexpected success response
   102  	unexpectedSuccess := result.(*AddOneDefault)
   103  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   104  }
   105  
   106  /*
   107  DestroyOne destroy one API
   108  */
   109  func (a *Client) DestroyOne(params *DestroyOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DestroyOneNoContent, error) {
   110  	// TODO: Validate the params before sending
   111  	if params == nil {
   112  		params = NewDestroyOneParams()
   113  	}
   114  	op := &runtime.ClientOperation{
   115  		ID:                 "destroyOne",
   116  		Method:             "DELETE",
   117  		PathPattern:        "/{id}",
   118  		ProducesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
   119  		ConsumesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
   120  		Schemes:            []string{"http", "https"},
   121  		Params:             params,
   122  		Reader:             &DestroyOneReader{formats: a.formats},
   123  		AuthInfo:           authInfo,
   124  		Context:            params.Context,
   125  		Client:             params.HTTPClient,
   126  	}
   127  	for _, opt := range opts {
   128  		opt(op)
   129  	}
   130  
   131  	result, err := a.transport.Submit(op)
   132  	if err != nil {
   133  		return nil, err
   134  	}
   135  	success, ok := result.(*DestroyOneNoContent)
   136  	if ok {
   137  		return success, nil
   138  	}
   139  	// unexpected success response
   140  	unexpectedSuccess := result.(*DestroyOneDefault)
   141  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   142  }
   143  
   144  /*
   145  Find find API
   146  */
   147  func (a *Client) Find(params *FindParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*FindOK, error) {
   148  	// TODO: Validate the params before sending
   149  	if params == nil {
   150  		params = NewFindParams()
   151  	}
   152  	op := &runtime.ClientOperation{
   153  		ID:                 "find",
   154  		Method:             "GET",
   155  		PathPattern:        "/",
   156  		ProducesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
   157  		ConsumesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
   158  		Schemes:            []string{"http", "https"},
   159  		Params:             params,
   160  		Reader:             &FindReader{formats: a.formats},
   161  		AuthInfo:           authInfo,
   162  		Context:            params.Context,
   163  		Client:             params.HTTPClient,
   164  	}
   165  	for _, opt := range opts {
   166  		opt(op)
   167  	}
   168  
   169  	result, err := a.transport.Submit(op)
   170  	if err != nil {
   171  		return nil, err
   172  	}
   173  	success, ok := result.(*FindOK)
   174  	if ok {
   175  		return success, nil
   176  	}
   177  	// unexpected success response
   178  	unexpectedSuccess := result.(*FindDefault)
   179  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   180  }
   181  
   182  /*
   183  UpdateOne update one API
   184  */
   185  func (a *Client) UpdateOne(params *UpdateOneParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateOneOK, error) {
   186  	// TODO: Validate the params before sending
   187  	if params == nil {
   188  		params = NewUpdateOneParams()
   189  	}
   190  	op := &runtime.ClientOperation{
   191  		ID:                 "updateOne",
   192  		Method:             "PUT",
   193  		PathPattern:        "/{id}",
   194  		ProducesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
   195  		ConsumesMediaTypes: []string{"application/io.swagger.examples.todo-list.v1+json"},
   196  		Schemes:            []string{"http", "https"},
   197  		Params:             params,
   198  		Reader:             &UpdateOneReader{formats: a.formats},
   199  		AuthInfo:           authInfo,
   200  		Context:            params.Context,
   201  		Client:             params.HTTPClient,
   202  	}
   203  	for _, opt := range opts {
   204  		opt(op)
   205  	}
   206  
   207  	result, err := a.transport.Submit(op)
   208  	if err != nil {
   209  		return nil, err
   210  	}
   211  	success, ok := result.(*UpdateOneOK)
   212  	if ok {
   213  		return success, nil
   214  	}
   215  	// unexpected success response
   216  	unexpectedSuccess := result.(*UpdateOneDefault)
   217  	return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
   218  }
   219  
   220  // SetTransport changes the transport on the client
   221  func (a *Client) SetTransport(transport runtime.ClientTransport) {
   222  	a.transport = transport
   223  }