github.com/circl-dev/go-swagger@v0.31.0/examples/stream-client/client/operations/operations_client.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package operations 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 "io" 11 12 "github.com/go-openapi/strfmt" 13 "github.com/circl-dev/runtime" 14 ) 15 16 // New creates a new operations API client. 17 func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService { 18 return &Client{transport: transport, formats: formats} 19 } 20 21 /* 22 Client for operations API 23 */ 24 type Client struct { 25 transport runtime.ClientTransport 26 formats strfmt.Registry 27 } 28 29 // ClientOption is the option for Client methods 30 type ClientOption func(*runtime.ClientOperation) 31 32 // ClientService is the interface for Client methods 33 type ClientService interface { 34 Chunked(params *ChunkedParams, writer io.Writer, opts ...ClientOption) (*ChunkedOK, error) 35 36 SetTransport(transport runtime.ClientTransport) 37 } 38 39 /* 40 Chunked chunkeds 41 42 delivers text/plain via Encoding: Chunked 43 */ 44 func (a *Client) Chunked(params *ChunkedParams, writer io.Writer, opts ...ClientOption) (*ChunkedOK, error) { 45 // TODO: Validate the params before sending 46 if params == nil { 47 params = NewChunkedParams() 48 } 49 op := &runtime.ClientOperation{ 50 ID: "chunked", 51 Method: "GET", 52 PathPattern: "/HTTP/ChunkedScript", 53 ProducesMediaTypes: []string{"application/json"}, 54 ConsumesMediaTypes: []string{"application/json"}, 55 Schemes: []string{"https"}, 56 Params: params, 57 Reader: &ChunkedReader{formats: a.formats, writer: writer}, 58 Context: params.Context, 59 Client: params.HTTPClient, 60 } 61 for _, opt := range opts { 62 opt(op) 63 } 64 65 result, err := a.transport.Submit(op) 66 if err != nil { 67 return nil, err 68 } 69 success, ok := result.(*ChunkedOK) 70 if ok { 71 return success, nil 72 } 73 // unexpected success response 74 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 75 msg := fmt.Sprintf("unexpected success response for chunked: API contract not enforced by server. Client expected to get an error, but got: %T", result) 76 panic(msg) 77 } 78 79 // SetTransport changes the transport on the client 80 func (a *Client) SetTransport(transport runtime.ClientTransport) { 81 a.transport = transport 82 }