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