github.com/go-swagger/go-swagger@v0.31.0/examples/cli/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 11 "github.com/go-openapi/runtime" 12 httptransport "github.com/go-openapi/runtime/client" 13 "github.com/go-openapi/strfmt" 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 // New creates a new operations API client with basic auth credentials. 22 // It takes the following parameters: 23 // - host: http host (github.com). 24 // - basePath: any base path for the API client ("/v1", "/v3"). 25 // - scheme: http scheme ("http", "https"). 26 // - user: user for basic authentication header. 27 // - password: password for basic authentication header. 28 func NewClientWithBasicAuth(host, basePath, scheme, user, password string) ClientService { 29 transport := httptransport.New(host, basePath, []string{scheme}) 30 transport.DefaultAuthentication = httptransport.BasicAuth(user, password) 31 return &Client{transport: transport, formats: strfmt.Default} 32 } 33 34 // New creates a new operations API client with a bearer token for authentication. 35 // It takes the following parameters: 36 // - host: http host (github.com). 37 // - basePath: any base path for the API client ("/v1", "/v3"). 38 // - scheme: http scheme ("http", "https"). 39 // - bearerToken: bearer token for Bearer authentication header. 40 func NewClientWithBearerToken(host, basePath, scheme, bearerToken string) ClientService { 41 transport := httptransport.New(host, basePath, []string{scheme}) 42 transport.DefaultAuthentication = httptransport.BearerToken(bearerToken) 43 return &Client{transport: transport, formats: strfmt.Default} 44 } 45 46 /* 47 Client for operations API 48 */ 49 type Client struct { 50 transport runtime.ClientTransport 51 formats strfmt.Registry 52 } 53 54 // ClientOption may be used to customize the behavior of Client methods. 55 type ClientOption func(*runtime.ClientOperation) 56 57 // This client is generated with a few options you might find useful for your swagger spec. 58 // 59 // Feel free to add you own set of options. 60 61 // WithContentType allows the client to force the Content-Type header 62 // to negotiate a specific Consumer from the server. 63 // 64 // You may use this option to set arbitrary extensions to your MIME media type. 65 func WithContentType(mime string) ClientOption { 66 return func(r *runtime.ClientOperation) { 67 r.ConsumesMediaTypes = []string{mime} 68 } 69 } 70 71 // WithContentTypeApplicationIoGoswaggerExamplesTodoListV1JSON sets the Content-Type header to "application/io.goswagger.examples.todo-list.v1+json". 72 func WithContentTypeApplicationIoGoswaggerExamplesTodoListV1JSON(r *runtime.ClientOperation) { 73 r.ConsumesMediaTypes = []string{"application/io.goswagger.examples.todo-list.v1+json"} 74 } 75 76 // WithContentTypeApplicationJSON sets the Content-Type header to "application/json". 77 func WithContentTypeApplicationJSON(r *runtime.ClientOperation) { 78 r.ConsumesMediaTypes = []string{"application/json"} 79 } 80 81 // WithAccept allows the client to force the Accept header 82 // to negotiate a specific Producer from the server. 83 // 84 // You may use this option to set arbitrary extensions to your MIME media type. 85 func WithAccept(mime string) ClientOption { 86 return func(r *runtime.ClientOperation) { 87 r.ProducesMediaTypes = []string{mime} 88 } 89 } 90 91 // WithAcceptApplicationIoGoswaggerExamplesTodoListV1JSON sets the Accept header to "application/io.goswagger.examples.todo-list.v1+json". 92 func WithAcceptApplicationIoGoswaggerExamplesTodoListV1JSON(r *runtime.ClientOperation) { 93 r.ProducesMediaTypes = []string{"application/io.goswagger.examples.todo-list.v1+json"} 94 } 95 96 // WithAcceptApplicationJSON sets the Accept header to "application/json". 97 func WithAcceptApplicationJSON(r *runtime.ClientOperation) { 98 r.ProducesMediaTypes = []string{"application/json"} 99 } 100 101 // ClientService is the interface for Client methods 102 type ClientService interface { 103 PutTest2766(params *PutTest2766Params, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutTest2766OK, error) 104 105 SetTransport(transport runtime.ClientTransport) 106 } 107 108 /* 109 PutTest2766 put test2766 API 110 */ 111 func (a *Client) PutTest2766(params *PutTest2766Params, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PutTest2766OK, error) { 112 // TODO: Validate the params before sending 113 if params == nil { 114 params = NewPutTest2766Params() 115 } 116 op := &runtime.ClientOperation{ 117 ID: "PutTest2766", 118 Method: "PUT", 119 PathPattern: "/test2766", 120 ProducesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 121 ConsumesMediaTypes: []string{"application/io.goswagger.examples.todo-list.v1+json"}, 122 Schemes: []string{"http"}, 123 Params: params, 124 Reader: &PutTest2766Reader{formats: a.formats}, 125 AuthInfo: authInfo, 126 Context: params.Context, 127 Client: params.HTTPClient, 128 } 129 for _, opt := range opts { 130 opt(op) 131 } 132 133 result, err := a.transport.Submit(op) 134 if err != nil { 135 return nil, err 136 } 137 success, ok := result.(*PutTest2766OK) 138 if ok { 139 return success, nil 140 } 141 // unexpected success response 142 // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 143 msg := fmt.Sprintf("unexpected success response for PutTest2766: API contract not enforced by server. Client expected to get an error, but got: %T", result) 144 panic(msg) 145 } 146 147 // SetTransport changes the transport on the client 148 func (a *Client) SetTransport(transport runtime.ClientTransport) { 149 a.transport = transport 150 }