github.com/go-swagger/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/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 Chunked(params *ChunkedParams, writer io.Writer, opts ...ClientOption) (*ChunkedOK, error) 61 62 SetTransport(transport runtime.ClientTransport) 63 } 64 65 /* 66 Chunked chunkeds 67 68 delivers text/plain via Encoding: Chunked 69 */ 70 func (a *Client) Chunked(params *ChunkedParams, writer io.Writer, opts ...ClientOption) (*ChunkedOK, error) { 71 // TODO: Validate the params before sending 72 if params == nil { 73 params = NewChunkedParams() 74 } 75 op := &runtime.ClientOperation{ 76 ID: "chunked", 77 Method: "GET", 78 PathPattern: "/HTTP/ChunkedScript", 79 ProducesMediaTypes: []string{"application/json"}, 80 ConsumesMediaTypes: []string{"application/json"}, 81 Schemes: []string{"https"}, 82 Params: params, 83 Reader: &ChunkedReader{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.(*ChunkedOK) 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 chunked: 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 }