github.com/circl-dev/go-swagger@v0.31.0/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/strfmt"
    12  	"github.com/circl-dev/runtime"
    13  )
    14  
    15  // New creates a new uploads API client.
    16  func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
    17  	return &Client{transport: transport, formats: formats}
    18  }
    19  
    20  /*
    21  Client for uploads API
    22  */
    23  type Client struct {
    24  	transport runtime.ClientTransport
    25  	formats   strfmt.Registry
    26  }
    27  
    28  // ClientOption is the option for Client methods
    29  type ClientOption func(*runtime.ClientOperation)
    30  
    31  // ClientService is the interface for Client methods
    32  type ClientService interface {
    33  	UploadFile(params *UploadFileParams, opts ...ClientOption) (*UploadFileOK, error)
    34  
    35  	SetTransport(transport runtime.ClientTransport)
    36  }
    37  
    38  /*
    39    UploadFile uploads
    40  */
    41  func (a *Client) UploadFile(params *UploadFileParams, opts ...ClientOption) (*UploadFileOK, error) {
    42  	// TODO: Validate the params before sending
    43  	if params == nil {
    44  		params = NewUploadFileParams()
    45  	}
    46  	op := &runtime.ClientOperation{
    47  		ID:                 "uploadFile",
    48  		Method:             "POST",
    49  		PathPattern:        "/upload",
    50  		ProducesMediaTypes: []string{"application/json"},
    51  		ConsumesMediaTypes: []string{"multipart/form-data"},
    52  		Schemes:            []string{"http"},
    53  		Params:             params,
    54  		Reader:             &UploadFileReader{formats: a.formats},
    55  		Context:            params.Context,
    56  		Client:             params.HTTPClient,
    57  	}
    58  	for _, opt := range opts {
    59  		opt(op)
    60  	}
    61  
    62  	result, err := a.transport.Submit(op)
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	success, ok := result.(*UploadFileOK)
    67  	if ok {
    68  		return success, nil
    69  	}
    70  	// unexpected success response
    71  	// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
    72  	msg := fmt.Sprintf("unexpected success response for uploadFile: API contract not enforced by server. Client expected to get an error, but got: %T", result)
    73  	panic(msg)
    74  }
    75  
    76  // SetTransport changes the transport on the client
    77  func (a *Client) SetTransport(transport runtime.ClientTransport) {
    78  	a.transport = transport
    79  }