github.com/circl-dev/go-swagger@v0.31.0/examples/stream-server/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 Elapse(params *ElapseParams, writer io.Writer, opts ...ClientOption) (*ElapseOK, error) 35 36 SetTransport(transport runtime.ClientTransport) 37 } 38 39 /* 40 Elapse counts down the number of seconds 41 42 Count down the seconds remaining 43 */ 44 func (a *Client) Elapse(params *ElapseParams, writer io.Writer, opts ...ClientOption) (*ElapseOK, error) { 45 // TODO: Validate the params before sending 46 if params == nil { 47 params = NewElapseParams() 48 } 49 op := &runtime.ClientOperation{ 50 ID: "elapse", 51 Method: "GET", 52 PathPattern: "/elapse/{length}", 53 ProducesMediaTypes: []string{"application/json"}, 54 ConsumesMediaTypes: []string{"application/json"}, 55 Schemes: []string{"http"}, 56 Params: params, 57 Reader: &ElapseReader{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.(*ElapseOK) 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 elapse: 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 }