add auto-gen client by swagger and a test
parent
076659539b
commit
b55b239c69
6
Makefile
6
Makefile
|
@ -1,7 +1,9 @@
|
|||
all:
|
||||
go build
|
||||
go build -v
|
||||
install:
|
||||
go install
|
||||
go install -v
|
||||
forcecheckinstall:
|
||||
GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger
|
||||
checkinstall:
|
||||
which swagger || GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger
|
||||
swagger:
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package client
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/runtime"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"microsrv/client/client/products"
|
||||
)
|
||||
|
||||
// Default product client HTTP client.
|
||||
var Default = NewHTTPClient(nil)
|
||||
|
||||
const (
|
||||
// DefaultHost is the default Host
|
||||
// found in Meta (info) section of spec file
|
||||
DefaultHost string = "localhost"
|
||||
// DefaultBasePath is the default BasePath
|
||||
// found in Meta (info) section of spec file
|
||||
DefaultBasePath string = "/"
|
||||
)
|
||||
|
||||
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
|
||||
var DefaultSchemes = []string{"http"}
|
||||
|
||||
// NewHTTPClient creates a new product client HTTP client.
|
||||
func NewHTTPClient(formats strfmt.Registry) *ProductClient {
|
||||
return NewHTTPClientWithConfig(formats, nil)
|
||||
}
|
||||
|
||||
// NewHTTPClientWithConfig creates a new product client HTTP client,
|
||||
// using a customizable transport config.
|
||||
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *ProductClient {
|
||||
// ensure nullable parameters have default
|
||||
if cfg == nil {
|
||||
cfg = DefaultTransportConfig()
|
||||
}
|
||||
|
||||
// create transport and client
|
||||
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
|
||||
return New(transport, formats)
|
||||
}
|
||||
|
||||
// New creates a new product client client
|
||||
func New(transport runtime.ClientTransport, formats strfmt.Registry) *ProductClient {
|
||||
// ensure nullable parameters have default
|
||||
if formats == nil {
|
||||
formats = strfmt.Default
|
||||
}
|
||||
|
||||
cli := new(ProductClient)
|
||||
cli.Transport = transport
|
||||
cli.Products = products.New(transport, formats)
|
||||
return cli
|
||||
}
|
||||
|
||||
// DefaultTransportConfig creates a TransportConfig with the
|
||||
// default settings taken from the meta section of the spec file.
|
||||
func DefaultTransportConfig() *TransportConfig {
|
||||
return &TransportConfig{
|
||||
Host: DefaultHost,
|
||||
BasePath: DefaultBasePath,
|
||||
Schemes: DefaultSchemes,
|
||||
}
|
||||
}
|
||||
|
||||
// TransportConfig contains the transport related info,
|
||||
// found in the meta section of the spec file.
|
||||
type TransportConfig struct {
|
||||
Host string
|
||||
BasePath string
|
||||
Schemes []string
|
||||
}
|
||||
|
||||
// WithHost overrides the default host,
|
||||
// provided by the meta section of the spec file.
|
||||
func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
|
||||
cfg.Host = host
|
||||
return cfg
|
||||
}
|
||||
|
||||
// WithBasePath overrides the default basePath,
|
||||
// provided by the meta section of the spec file.
|
||||
func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
|
||||
cfg.BasePath = basePath
|
||||
return cfg
|
||||
}
|
||||
|
||||
// WithSchemes overrides the default schemes,
|
||||
// provided by the meta section of the spec file.
|
||||
func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
|
||||
cfg.Schemes = schemes
|
||||
return cfg
|
||||
}
|
||||
|
||||
// ProductClient is a client for product client
|
||||
type ProductClient struct {
|
||||
Products products.ClientService
|
||||
|
||||
Transport runtime.ClientTransport
|
||||
}
|
||||
|
||||
// SetTransport changes the transport on the client and all its subresources
|
||||
func (c *ProductClient) SetTransport(transport runtime.ClientTransport) {
|
||||
c.Transport = transport
|
||||
c.Products.SetTransport(transport)
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"microsrv/client/models"
|
||||
)
|
||||
|
||||
// NewAddProductParams creates a new AddProductParams object
|
||||
// with the default values initialized.
|
||||
func NewAddProductParams() *AddProductParams {
|
||||
var ()
|
||||
return &AddProductParams{
|
||||
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAddProductParamsWithTimeout creates a new AddProductParams object
|
||||
// with the default values initialized, and the ability to set a timeout on a request
|
||||
func NewAddProductParamsWithTimeout(timeout time.Duration) *AddProductParams {
|
||||
var ()
|
||||
return &AddProductParams{
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAddProductParamsWithContext creates a new AddProductParams object
|
||||
// with the default values initialized, and the ability to set a context for a request
|
||||
func NewAddProductParamsWithContext(ctx context.Context) *AddProductParams {
|
||||
var ()
|
||||
return &AddProductParams{
|
||||
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewAddProductParamsWithHTTPClient creates a new AddProductParams object
|
||||
// with the default values initialized, and the ability to set a custom HTTPClient for a request
|
||||
func NewAddProductParamsWithHTTPClient(client *http.Client) *AddProductParams {
|
||||
var ()
|
||||
return &AddProductParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*AddProductParams contains all the parameters to send to the API endpoint
|
||||
for the add product operation typically these are written to a http.Request
|
||||
*/
|
||||
type AddProductParams struct {
|
||||
|
||||
/*Body
|
||||
Product data structure to Update or Add.
|
||||
Note: the id field is ignored by update and create operations
|
||||
|
||||
*/
|
||||
Body *models.Product
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the add product params
|
||||
func (o *AddProductParams) WithTimeout(timeout time.Duration) *AddProductParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the add product params
|
||||
func (o *AddProductParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the add product params
|
||||
func (o *AddProductParams) WithContext(ctx context.Context) *AddProductParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the add product params
|
||||
func (o *AddProductParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the add product params
|
||||
func (o *AddProductParams) WithHTTPClient(client *http.Client) *AddProductParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the add product params
|
||||
func (o *AddProductParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the add product params
|
||||
func (o *AddProductParams) WithBody(body *models.Product) *AddProductParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the add product params
|
||||
func (o *AddProductParams) SetBody(body *models.Product) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *AddProductParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
if o.Body != nil {
|
||||
if err := r.SetBodyParam(o.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"microsrv/client/models"
|
||||
)
|
||||
|
||||
// AddProductReader is a Reader for the AddProduct structure.
|
||||
type AddProductReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *AddProductReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewAddProductOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 422:
|
||||
result := NewAddProductUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 501:
|
||||
result := NewAddProductNotImplemented()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
|
||||
default:
|
||||
return nil, runtime.NewAPIError("unknown error", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewAddProductOK creates a AddProductOK with default headers values
|
||||
func NewAddProductOK() *AddProductOK {
|
||||
return &AddProductOK{}
|
||||
}
|
||||
|
||||
/*AddProductOK handles this case with default header values.
|
||||
|
||||
Data structure representing a single product
|
||||
*/
|
||||
type AddProductOK struct {
|
||||
Payload *models.Product
|
||||
}
|
||||
|
||||
func (o *AddProductOK) Error() string {
|
||||
return fmt.Sprintf("[POST /products][%d] addProductOK %+v", 200, o.Payload)
|
||||
}
|
||||
|
||||
func (o *AddProductOK) GetPayload() *models.Product {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *AddProductOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.Product)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewAddProductUnprocessableEntity creates a AddProductUnprocessableEntity with default headers values
|
||||
func NewAddProductUnprocessableEntity() *AddProductUnprocessableEntity {
|
||||
return &AddProductUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*AddProductUnprocessableEntity handles this case with default header values.
|
||||
|
||||
Validation errors defined as an array of strings
|
||||
*/
|
||||
type AddProductUnprocessableEntity struct {
|
||||
Payload *models.ValidationError
|
||||
}
|
||||
|
||||
func (o *AddProductUnprocessableEntity) Error() string {
|
||||
return fmt.Sprintf("[POST /products][%d] addProductUnprocessableEntity %+v", 422, o.Payload)
|
||||
}
|
||||
|
||||
func (o *AddProductUnprocessableEntity) GetPayload() *models.ValidationError {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *AddProductUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.ValidationError)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewAddProductNotImplemented creates a AddProductNotImplemented with default headers values
|
||||
func NewAddProductNotImplemented() *AddProductNotImplemented {
|
||||
return &AddProductNotImplemented{}
|
||||
}
|
||||
|
||||
/*AddProductNotImplemented handles this case with default header values.
|
||||
|
||||
Generic error message returned as a string
|
||||
*/
|
||||
type AddProductNotImplemented struct {
|
||||
Payload *models.GenericError
|
||||
}
|
||||
|
||||
func (o *AddProductNotImplemented) Error() string {
|
||||
return fmt.Sprintf("[POST /products][%d] addProductNotImplemented %+v", 501, o.Payload)
|
||||
}
|
||||
|
||||
func (o *AddProductNotImplemented) GetPayload() *models.GenericError {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *AddProductNotImplemented) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.GenericError)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
|
||||
"microsrv/client/models"
|
||||
)
|
||||
|
||||
// NewDeleteProductParams creates a new DeleteProductParams object
|
||||
// with the default values initialized.
|
||||
func NewDeleteProductParams() *DeleteProductParams {
|
||||
var ()
|
||||
return &DeleteProductParams{
|
||||
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewDeleteProductParamsWithTimeout creates a new DeleteProductParams object
|
||||
// with the default values initialized, and the ability to set a timeout on a request
|
||||
func NewDeleteProductParamsWithTimeout(timeout time.Duration) *DeleteProductParams {
|
||||
var ()
|
||||
return &DeleteProductParams{
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewDeleteProductParamsWithContext creates a new DeleteProductParams object
|
||||
// with the default values initialized, and the ability to set a context for a request
|
||||
func NewDeleteProductParamsWithContext(ctx context.Context) *DeleteProductParams {
|
||||
var ()
|
||||
return &DeleteProductParams{
|
||||
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewDeleteProductParamsWithHTTPClient creates a new DeleteProductParams object
|
||||
// with the default values initialized, and the ability to set a custom HTTPClient for a request
|
||||
func NewDeleteProductParamsWithHTTPClient(client *http.Client) *DeleteProductParams {
|
||||
var ()
|
||||
return &DeleteProductParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*DeleteProductParams contains all the parameters to send to the API endpoint
|
||||
for the delete product operation typically these are written to a http.Request
|
||||
*/
|
||||
type DeleteProductParams struct {
|
||||
|
||||
/*Body
|
||||
Product data structure to Update or Add.
|
||||
Note: the id field is ignored by update and create operations
|
||||
|
||||
*/
|
||||
Body *models.Product
|
||||
/*ID
|
||||
The id of the product that is operated on
|
||||
|
||||
*/
|
||||
ID int64
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the delete product params
|
||||
func (o *DeleteProductParams) WithTimeout(timeout time.Duration) *DeleteProductParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the delete product params
|
||||
func (o *DeleteProductParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the delete product params
|
||||
func (o *DeleteProductParams) WithContext(ctx context.Context) *DeleteProductParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the delete product params
|
||||
func (o *DeleteProductParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the delete product params
|
||||
func (o *DeleteProductParams) WithHTTPClient(client *http.Client) *DeleteProductParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the delete product params
|
||||
func (o *DeleteProductParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithBody adds the body to the delete product params
|
||||
func (o *DeleteProductParams) WithBody(body *models.Product) *DeleteProductParams {
|
||||
o.SetBody(body)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetBody adds the body to the delete product params
|
||||
func (o *DeleteProductParams) SetBody(body *models.Product) {
|
||||
o.Body = body
|
||||
}
|
||||
|
||||
// WithID adds the id to the delete product params
|
||||
func (o *DeleteProductParams) WithID(id int64) *DeleteProductParams {
|
||||
o.SetID(id)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetID adds the id to the delete product params
|
||||
func (o *DeleteProductParams) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *DeleteProductParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
if o.Body != nil {
|
||||
if err := r.SetBodyParam(o.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// path param id
|
||||
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"microsrv/client/models"
|
||||
)
|
||||
|
||||
// DeleteProductReader is a Reader for the DeleteProduct structure.
|
||||
type DeleteProductReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *DeleteProductReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 201:
|
||||
result := NewDeleteProductCreated()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewDeleteProductNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 501:
|
||||
result := NewDeleteProductNotImplemented()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
|
||||
default:
|
||||
return nil, runtime.NewAPIError("unknown error", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewDeleteProductCreated creates a DeleteProductCreated with default headers values
|
||||
func NewDeleteProductCreated() *DeleteProductCreated {
|
||||
return &DeleteProductCreated{}
|
||||
}
|
||||
|
||||
/*DeleteProductCreated handles this case with default header values.
|
||||
|
||||
No content is returned by this API endpoint
|
||||
*/
|
||||
type DeleteProductCreated struct {
|
||||
}
|
||||
|
||||
func (o *DeleteProductCreated) Error() string {
|
||||
return fmt.Sprintf("[DELETE /products/{id}][%d] deleteProductCreated ", 201)
|
||||
}
|
||||
|
||||
func (o *DeleteProductCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewDeleteProductNotFound creates a DeleteProductNotFound with default headers values
|
||||
func NewDeleteProductNotFound() *DeleteProductNotFound {
|
||||
return &DeleteProductNotFound{}
|
||||
}
|
||||
|
||||
/*DeleteProductNotFound handles this case with default header values.
|
||||
|
||||
Generic error message returned as a string
|
||||
*/
|
||||
type DeleteProductNotFound struct {
|
||||
Payload *models.GenericError
|
||||
}
|
||||
|
||||
func (o *DeleteProductNotFound) Error() string {
|
||||
return fmt.Sprintf("[DELETE /products/{id}][%d] deleteProductNotFound %+v", 404, o.Payload)
|
||||
}
|
||||
|
||||
func (o *DeleteProductNotFound) GetPayload() *models.GenericError {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *DeleteProductNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.GenericError)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewDeleteProductNotImplemented creates a DeleteProductNotImplemented with default headers values
|
||||
func NewDeleteProductNotImplemented() *DeleteProductNotImplemented {
|
||||
return &DeleteProductNotImplemented{}
|
||||
}
|
||||
|
||||
/*DeleteProductNotImplemented handles this case with default header values.
|
||||
|
||||
Generic error message returned as a string
|
||||
*/
|
||||
type DeleteProductNotImplemented struct {
|
||||
Payload *models.GenericError
|
||||
}
|
||||
|
||||
func (o *DeleteProductNotImplemented) Error() string {
|
||||
return fmt.Sprintf("[DELETE /products/{id}][%d] deleteProductNotImplemented %+v", 501, o.Payload)
|
||||
}
|
||||
|
||||
func (o *DeleteProductNotImplemented) GetPayload() *models.GenericError {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *DeleteProductNotImplemented) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.GenericError)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// NewGetProductParams creates a new GetProductParams object
|
||||
// with the default values initialized.
|
||||
func NewGetProductParams() *GetProductParams {
|
||||
var ()
|
||||
return &GetProductParams{
|
||||
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductParamsWithTimeout creates a new GetProductParams object
|
||||
// with the default values initialized, and the ability to set a timeout on a request
|
||||
func NewGetProductParamsWithTimeout(timeout time.Duration) *GetProductParams {
|
||||
var ()
|
||||
return &GetProductParams{
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductParamsWithContext creates a new GetProductParams object
|
||||
// with the default values initialized, and the ability to set a context for a request
|
||||
func NewGetProductParamsWithContext(ctx context.Context) *GetProductParams {
|
||||
var ()
|
||||
return &GetProductParams{
|
||||
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductParamsWithHTTPClient creates a new GetProductParams object
|
||||
// with the default values initialized, and the ability to set a custom HTTPClient for a request
|
||||
func NewGetProductParamsWithHTTPClient(client *http.Client) *GetProductParams {
|
||||
var ()
|
||||
return &GetProductParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*GetProductParams contains all the parameters to send to the API endpoint
|
||||
for the get product operation typically these are written to a http.Request
|
||||
*/
|
||||
type GetProductParams struct {
|
||||
|
||||
/*ID
|
||||
The id of the product that is operated on
|
||||
|
||||
*/
|
||||
ID int64
|
||||
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the get product params
|
||||
func (o *GetProductParams) WithTimeout(timeout time.Duration) *GetProductParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the get product params
|
||||
func (o *GetProductParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the get product params
|
||||
func (o *GetProductParams) WithContext(ctx context.Context) *GetProductParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the get product params
|
||||
func (o *GetProductParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the get product params
|
||||
func (o *GetProductParams) WithHTTPClient(client *http.Client) *GetProductParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the get product params
|
||||
func (o *GetProductParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WithID adds the id to the get product params
|
||||
func (o *GetProductParams) WithID(id int64) *GetProductParams {
|
||||
o.SetID(id)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetID adds the id to the get product params
|
||||
func (o *GetProductParams) SetID(id int64) {
|
||||
o.ID = id
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *GetProductParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
// path param id
|
||||
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"microsrv/client/models"
|
||||
)
|
||||
|
||||
// GetProductReader is a Reader for the GetProduct structure.
|
||||
type GetProductReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *GetProductReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewGetProductOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewGetProductNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
|
||||
default:
|
||||
return nil, runtime.NewAPIError("unknown error", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductOK creates a GetProductOK with default headers values
|
||||
func NewGetProductOK() *GetProductOK {
|
||||
return &GetProductOK{}
|
||||
}
|
||||
|
||||
/*GetProductOK handles this case with default header values.
|
||||
|
||||
Data structure representing a single product
|
||||
*/
|
||||
type GetProductOK struct {
|
||||
Payload *models.Product
|
||||
}
|
||||
|
||||
func (o *GetProductOK) Error() string {
|
||||
return fmt.Sprintf("[GET /products/{id}][%d] getProductOK %+v", 200, o.Payload)
|
||||
}
|
||||
|
||||
func (o *GetProductOK) GetPayload() *models.Product {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *GetProductOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.Product)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewGetProductNotFound creates a GetProductNotFound with default headers values
|
||||
func NewGetProductNotFound() *GetProductNotFound {
|
||||
return &GetProductNotFound{}
|
||||
}
|
||||
|
||||
/*GetProductNotFound handles this case with default header values.
|
||||
|
||||
Generic error message returned as a string
|
||||
*/
|
||||
type GetProductNotFound struct {
|
||||
Payload *models.GenericError
|
||||
}
|
||||
|
||||
func (o *GetProductNotFound) Error() string {
|
||||
return fmt.Sprintf("[GET /products/{id}][%d] getProductNotFound %+v", 404, o.Payload)
|
||||
}
|
||||
|
||||
func (o *GetProductNotFound) GetPayload() *models.GenericError {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *GetProductNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.GenericError)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// NewGetProductsParams creates a new GetProductsParams object
|
||||
// with the default values initialized.
|
||||
func NewGetProductsParams() *GetProductsParams {
|
||||
|
||||
return &GetProductsParams{
|
||||
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductsParamsWithTimeout creates a new GetProductsParams object
|
||||
// with the default values initialized, and the ability to set a timeout on a request
|
||||
func NewGetProductsParamsWithTimeout(timeout time.Duration) *GetProductsParams {
|
||||
|
||||
return &GetProductsParams{
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductsParamsWithContext creates a new GetProductsParams object
|
||||
// with the default values initialized, and the ability to set a context for a request
|
||||
func NewGetProductsParamsWithContext(ctx context.Context) *GetProductsParams {
|
||||
|
||||
return &GetProductsParams{
|
||||
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductsParamsWithHTTPClient creates a new GetProductsParams object
|
||||
// with the default values initialized, and the ability to set a custom HTTPClient for a request
|
||||
func NewGetProductsParamsWithHTTPClient(client *http.Client) *GetProductsParams {
|
||||
|
||||
return &GetProductsParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*GetProductsParams contains all the parameters to send to the API endpoint
|
||||
for the get products operation typically these are written to a http.Request
|
||||
*/
|
||||
type GetProductsParams struct {
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the get products params
|
||||
func (o *GetProductsParams) WithTimeout(timeout time.Duration) *GetProductsParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the get products params
|
||||
func (o *GetProductsParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the get products params
|
||||
func (o *GetProductsParams) WithContext(ctx context.Context) *GetProductsParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the get products params
|
||||
func (o *GetProductsParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the get products params
|
||||
func (o *GetProductsParams) WithHTTPClient(client *http.Client) *GetProductsParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the get products params
|
||||
func (o *GetProductsParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *GetProductsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"microsrv/client/models"
|
||||
)
|
||||
|
||||
// GetProductsReader is a Reader for the GetProducts structure.
|
||||
type GetProductsReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *GetProductsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 200:
|
||||
result := NewGetProductsOK()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
|
||||
default:
|
||||
return nil, runtime.NewAPIError("unknown error", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewGetProductsOK creates a GetProductsOK with default headers values
|
||||
func NewGetProductsOK() *GetProductsOK {
|
||||
return &GetProductsOK{}
|
||||
}
|
||||
|
||||
/*GetProductsOK handles this case with default header values.
|
||||
|
||||
A list of products
|
||||
*/
|
||||
type GetProductsOK struct {
|
||||
Payload []*models.Product
|
||||
}
|
||||
|
||||
func (o *GetProductsOK) Error() string {
|
||||
return fmt.Sprintf("[GET /products][%d] getProductsOK %+v", 200, o.Payload)
|
||||
}
|
||||
|
||||
func (o *GetProductsOK) GetPayload() []*models.Product {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *GetProductsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// New creates a new products API client.
|
||||
func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService {
|
||||
return &Client{transport: transport, formats: formats}
|
||||
}
|
||||
|
||||
/*
|
||||
Client for products API
|
||||
*/
|
||||
type Client struct {
|
||||
transport runtime.ClientTransport
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ClientService is the interface for Client methods
|
||||
type ClientService interface {
|
||||
AddProduct(params *AddProductParams) (*AddProductOK, error)
|
||||
|
||||
DeleteProduct(params *DeleteProductParams) (*DeleteProductCreated, error)
|
||||
|
||||
GetProduct(params *GetProductParams) (*GetProductOK, error)
|
||||
|
||||
GetProducts(params *GetProductsParams) (*GetProductsOK, error)
|
||||
|
||||
UpdateProduct(params *UpdateProductParams) (*UpdateProductCreated, error)
|
||||
|
||||
SetTransport(transport runtime.ClientTransport)
|
||||
}
|
||||
|
||||
/*
|
||||
AddProduct Create a new product
|
||||
*/
|
||||
func (a *Client) AddProduct(params *AddProductParams) (*AddProductOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewAddProductParams()
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(&runtime.ClientOperation{
|
||||
ID: "addProduct",
|
||||
Method: "POST",
|
||||
PathPattern: "/products",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http"},
|
||||
Params: params,
|
||||
Reader: &AddProductReader{formats: a.formats},
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*AddProductOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for addProduct: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
DeleteProduct Update a products details
|
||||
*/
|
||||
func (a *Client) DeleteProduct(params *DeleteProductParams) (*DeleteProductCreated, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewDeleteProductParams()
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(&runtime.ClientOperation{
|
||||
ID: "deleteProduct",
|
||||
Method: "DELETE",
|
||||
PathPattern: "/products/{id}",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http"},
|
||||
Params: params,
|
||||
Reader: &DeleteProductReader{formats: a.formats},
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*DeleteProductCreated)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for deleteProduct: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
GetProduct Return a single product from the data store
|
||||
*/
|
||||
func (a *Client) GetProduct(params *GetProductParams) (*GetProductOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewGetProductParams()
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(&runtime.ClientOperation{
|
||||
ID: "getProduct",
|
||||
Method: "GET",
|
||||
PathPattern: "/products/{id}",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http"},
|
||||
Params: params,
|
||||
Reader: &GetProductReader{formats: a.formats},
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*GetProductOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for getProduct: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
GetProducts Return a list of products from the data store
|
||||
*/
|
||||
func (a *Client) GetProducts(params *GetProductsParams) (*GetProductsOK, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewGetProductsParams()
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(&runtime.ClientOperation{
|
||||
ID: "getProducts",
|
||||
Method: "GET",
|
||||
PathPattern: "/products",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http"},
|
||||
Params: params,
|
||||
Reader: &GetProductsReader{formats: a.formats},
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*GetProductsOK)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for getProducts: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
/*
|
||||
UpdateProduct Replaces one product
|
||||
*/
|
||||
func (a *Client) UpdateProduct(params *UpdateProductParams) (*UpdateProductCreated, error) {
|
||||
// TODO: Validate the params before sending
|
||||
if params == nil {
|
||||
params = NewUpdateProductParams()
|
||||
}
|
||||
|
||||
result, err := a.transport.Submit(&runtime.ClientOperation{
|
||||
ID: "updateProduct",
|
||||
Method: "PUT",
|
||||
PathPattern: "/products",
|
||||
ProducesMediaTypes: []string{"application/json"},
|
||||
ConsumesMediaTypes: []string{"application/json"},
|
||||
Schemes: []string{"http"},
|
||||
Params: params,
|
||||
Reader: &UpdateProductReader{formats: a.formats},
|
||||
Context: params.Context,
|
||||
Client: params.HTTPClient,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success, ok := result.(*UpdateProductCreated)
|
||||
if ok {
|
||||
return success, nil
|
||||
}
|
||||
// unexpected success response
|
||||
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
|
||||
msg := fmt.Sprintf("unexpected success response for updateProduct: API contract not enforced by server. Client expected to get an error, but got: %T", result)
|
||||
panic(msg)
|
||||
}
|
||||
|
||||
// SetTransport changes the transport on the client
|
||||
func (a *Client) SetTransport(transport runtime.ClientTransport) {
|
||||
a.transport = transport
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
cr "github.com/go-openapi/runtime/client"
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
// NewUpdateProductParams creates a new UpdateProductParams object
|
||||
// with the default values initialized.
|
||||
func NewUpdateProductParams() *UpdateProductParams {
|
||||
|
||||
return &UpdateProductParams{
|
||||
|
||||
timeout: cr.DefaultTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewUpdateProductParamsWithTimeout creates a new UpdateProductParams object
|
||||
// with the default values initialized, and the ability to set a timeout on a request
|
||||
func NewUpdateProductParamsWithTimeout(timeout time.Duration) *UpdateProductParams {
|
||||
|
||||
return &UpdateProductParams{
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// NewUpdateProductParamsWithContext creates a new UpdateProductParams object
|
||||
// with the default values initialized, and the ability to set a context for a request
|
||||
func NewUpdateProductParamsWithContext(ctx context.Context) *UpdateProductParams {
|
||||
|
||||
return &UpdateProductParams{
|
||||
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// NewUpdateProductParamsWithHTTPClient creates a new UpdateProductParams object
|
||||
// with the default values initialized, and the ability to set a custom HTTPClient for a request
|
||||
func NewUpdateProductParamsWithHTTPClient(client *http.Client) *UpdateProductParams {
|
||||
|
||||
return &UpdateProductParams{
|
||||
HTTPClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
/*UpdateProductParams contains all the parameters to send to the API endpoint
|
||||
for the update product operation typically these are written to a http.Request
|
||||
*/
|
||||
type UpdateProductParams struct {
|
||||
timeout time.Duration
|
||||
Context context.Context
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
// WithTimeout adds the timeout to the update product params
|
||||
func (o *UpdateProductParams) WithTimeout(timeout time.Duration) *UpdateProductParams {
|
||||
o.SetTimeout(timeout)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetTimeout adds the timeout to the update product params
|
||||
func (o *UpdateProductParams) SetTimeout(timeout time.Duration) {
|
||||
o.timeout = timeout
|
||||
}
|
||||
|
||||
// WithContext adds the context to the update product params
|
||||
func (o *UpdateProductParams) WithContext(ctx context.Context) *UpdateProductParams {
|
||||
o.SetContext(ctx)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetContext adds the context to the update product params
|
||||
func (o *UpdateProductParams) SetContext(ctx context.Context) {
|
||||
o.Context = ctx
|
||||
}
|
||||
|
||||
// WithHTTPClient adds the HTTPClient to the update product params
|
||||
func (o *UpdateProductParams) WithHTTPClient(client *http.Client) *UpdateProductParams {
|
||||
o.SetHTTPClient(client)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetHTTPClient adds the HTTPClient to the update product params
|
||||
func (o *UpdateProductParams) SetHTTPClient(client *http.Client) {
|
||||
o.HTTPClient = client
|
||||
}
|
||||
|
||||
// WriteToRequest writes these params to a swagger request
|
||||
func (o *UpdateProductParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
|
||||
|
||||
if err := r.SetTimeout(o.timeout); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []error
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
package products
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"microsrv/client/models"
|
||||
)
|
||||
|
||||
// UpdateProductReader is a Reader for the UpdateProduct structure.
|
||||
type UpdateProductReader struct {
|
||||
formats strfmt.Registry
|
||||
}
|
||||
|
||||
// ReadResponse reads a server response into the received o.
|
||||
func (o *UpdateProductReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
|
||||
switch response.Code() {
|
||||
case 201:
|
||||
result := NewUpdateProductCreated()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewUpdateProductNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 422:
|
||||
result := NewUpdateProductUnprocessableEntity()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
|
||||
default:
|
||||
return nil, runtime.NewAPIError("unknown error", response, response.Code())
|
||||
}
|
||||
}
|
||||
|
||||
// NewUpdateProductCreated creates a UpdateProductCreated with default headers values
|
||||
func NewUpdateProductCreated() *UpdateProductCreated {
|
||||
return &UpdateProductCreated{}
|
||||
}
|
||||
|
||||
/*UpdateProductCreated handles this case with default header values.
|
||||
|
||||
No content is returned by this API endpoint
|
||||
*/
|
||||
type UpdateProductCreated struct {
|
||||
}
|
||||
|
||||
func (o *UpdateProductCreated) Error() string {
|
||||
return fmt.Sprintf("[PUT /products][%d] updateProductCreated ", 201)
|
||||
}
|
||||
|
||||
func (o *UpdateProductCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewUpdateProductNotFound creates a UpdateProductNotFound with default headers values
|
||||
func NewUpdateProductNotFound() *UpdateProductNotFound {
|
||||
return &UpdateProductNotFound{}
|
||||
}
|
||||
|
||||
/*UpdateProductNotFound handles this case with default header values.
|
||||
|
||||
Generic error message returned as a string
|
||||
*/
|
||||
type UpdateProductNotFound struct {
|
||||
Payload *models.GenericError
|
||||
}
|
||||
|
||||
func (o *UpdateProductNotFound) Error() string {
|
||||
return fmt.Sprintf("[PUT /products][%d] updateProductNotFound %+v", 404, o.Payload)
|
||||
}
|
||||
|
||||
func (o *UpdateProductNotFound) GetPayload() *models.GenericError {
|
||||
return o.Payload
|
||||
}
|
||||
|
||||
func (o *UpdateProductNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
o.Payload = new(models.GenericError)
|
||||
|
||||
// response payload
|
||||
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewUpdateProductUnprocessableEntity creates a UpdateProductUnprocessableEntity with default headers values
|
||||
func NewUpdateProductUnprocessableEntity() *UpdateProductUnprocessableEntity {
|
||||
return &UpdateProductUnprocessableEntity{}
|
||||
}
|
||||
|
||||
/*UpdateProductUnprocessableEntity handles this case with default header values.
|
||||
|
||||
Validation errors defined as an |