github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/file-server/client/uploads/uploads_client.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package uploads
     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  	"fmt"
    10  
    11  	"github.com/go-openapi/runtime"
    12  	httptransport "github.com/go-openapi/runtime/client"
    13  	"github.com/go-openapi/strfmt"
    14  )
    15  
    16  // New creates a new uploads API client.
    17  func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
    18  	return &Client{transport: transport, formats: formats}
    19  }
    20  
    21  // New creates a new uploads API client with basic auth credentials.
    22  // It takes the following parameters:
    23  // - host: http host (github.com).
    24  // - basePath: any base path for the API client ("/v1", "/v3").
    25  // - scheme: http scheme ("http", "https").
    26  // - user: user for basic authentication header.
    27  // - password: password for basic authentication header.
    28  func NewClientWithBasicAuth(host, basePath, scheme, user, password string) ClientService {
    29  	transport := httptransport.New(host, basePath, []string{scheme})
    30  	transport.DefaultAuthentication = httptransport.BasicAuth(user, password)
    31  	return &Client{transport: transport, formats: strfmt.Default}
    32  }
    33  
    34  // New creates a new uploads API client with a bearer token for authentication.
    35  // It takes the following parameters:
    36  // - host: http host (github.com).
    37  // - basePath: any base path for the API client ("/v1", "/v3").
    38  // - scheme: http scheme ("http", "https").
    39  // - bearerToken: bearer token for Bearer authentication header.
    40  func NewClientWithBearerToken(host, basePath, scheme, bearerToken string) ClientService {
    41  	transport := httptransport.New(host, basePath, []string{scheme})
    42  	transport.DefaultAuthentication = httptransport.BearerToken(bearerToken)
    43  	return &Client{transport: transport, formats: strfmt.Default}
    44  }
    45  
    46  /*
    47  Client for uploads API
    48  */
    49  type Client struct {
    50  	transport runtime.ClientTransport
    51  	formats   strfmt.Registry
    52  }
    53  
    54  // ClientOption is the option for Client methods
    55  type ClientOption func(*runtime.ClientOperation)
    56  
    57  // ClientService is the interface for Client methods
    58  type ClientService interface {
    59  	UploadFile(params *UploadFileParams, opts ...ClientOption) (*UploadFileOK, error)
    60  
    61  	SetTransport(transport runtime.ClientTransport)
    62  }
    63  
    64  /*
    65  UploadFile uploads
    66  */
    67  func (a *Client) UploadFile(params *UploadFileParams, opts ...ClientOption) (*UploadFileOK, error) {
    68  	// TODO: Validate the params before sending
    69  	if params == nil {
    70  		params = NewUploadFileParams()
    71  	}
    72  	op := &runtime.ClientOperation{
    73  		ID:                 "uploadFile",
    74  		Method:             "POST",
    75  		PathPattern:        "/upload",
    76  		ProducesMediaTypes: []string{"application/json"},
    77  		ConsumesMediaTypes: []string{"multipart/form-data"},
    78  		Schemes:            []string{"http"},
    79  		Params:             params,
    80  		Reader:             &UploadFileReader{formats: a.formats},
    81  		Context:            params.Context,
    82  		Client:             params.HTTPClient,
    83  	}
    84  	for _, opt := range opts {
    85  		opt(op)
    86  	}
    87  
    88  	result, err := a.transport.Submit(op)
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  	success, ok := result.(*UploadFileOK)
    93  	if ok {
    94  		return success, nil
    95  	}
    96  	// unexpected success response
    97  	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
    98  	msg := fmt.Sprintf("unexpected success response for uploadFile: API contract not enforced by server. Client expected to get an error, but got: %T", result)
    99  	panic(msg)
   100  }
   101  
   102  // SetTransport changes the transport on the client
   103  func (a *Client) SetTransport(transport runtime.ClientTransport) {
   104  	a.transport = transport
   105  }