github.com/circl-dev/go-swagger@v0.31.0/examples/task-tracker/client/tasks/add_comment_to_task_responses.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package tasks
     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  	"context"
    10  	"fmt"
    11  	"io"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/strfmt"
    15  	"github.com/go-openapi/swag"
    16  	"github.com/circl-dev/runtime"
    17  	"github.com/circl-dev/validate"
    18  
    19  	"github.com/circl-dev/go-swagger/examples/task-tracker/models"
    20  )
    21  
    22  // AddCommentToTaskReader is a Reader for the AddCommentToTask structure.
    23  type AddCommentToTaskReader struct {
    24  	formats strfmt.Registry
    25  }
    26  
    27  // ReadResponse reads a server response into the received o.
    28  func (o *AddCommentToTaskReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
    29  	switch response.Code() {
    30  	case 201:
    31  		result := NewAddCommentToTaskCreated()
    32  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    33  			return nil, err
    34  		}
    35  		return result, nil
    36  	default:
    37  		result := NewAddCommentToTaskDefault(response.Code())
    38  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    39  			return nil, err
    40  		}
    41  		if response.Code()/100 == 2 {
    42  			return result, nil
    43  		}
    44  		return nil, result
    45  	}
    46  }
    47  
    48  // NewAddCommentToTaskCreated creates a AddCommentToTaskCreated with default headers values
    49  func NewAddCommentToTaskCreated() *AddCommentToTaskCreated {
    50  	return &AddCommentToTaskCreated{}
    51  }
    52  
    53  /* AddCommentToTaskCreated describes a response with status code 201, with default header values.
    54  
    55  Comment added
    56  */
    57  type AddCommentToTaskCreated struct {
    58  }
    59  
    60  func (o *AddCommentToTaskCreated) Error() string {
    61  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTaskCreated ", 201)
    62  }
    63  
    64  func (o *AddCommentToTaskCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    65  
    66  	return nil
    67  }
    68  
    69  // NewAddCommentToTaskDefault creates a AddCommentToTaskDefault with default headers values
    70  func NewAddCommentToTaskDefault(code int) *AddCommentToTaskDefault {
    71  	return &AddCommentToTaskDefault{
    72  		_statusCode: code,
    73  	}
    74  }
    75  
    76  /* AddCommentToTaskDefault describes a response with status code -1, with default header values.
    77  
    78  Error response
    79  */
    80  type AddCommentToTaskDefault struct {
    81  	_statusCode int
    82  	XErrorCode  string
    83  
    84  	Payload *models.Error
    85  }
    86  
    87  // Code gets the status code for the add comment to task default response
    88  func (o *AddCommentToTaskDefault) Code() int {
    89  	return o._statusCode
    90  }
    91  
    92  func (o *AddCommentToTaskDefault) Error() string {
    93  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTask default  %+v", o._statusCode, o.Payload)
    94  }
    95  func (o *AddCommentToTaskDefault) GetPayload() *models.Error {
    96  	return o.Payload
    97  }
    98  
    99  func (o *AddCommentToTaskDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   100  
   101  	// hydrates response header X-Error-Code
   102  	hdrXErrorCode := response.GetHeader("X-Error-Code")
   103  
   104  	if hdrXErrorCode != "" {
   105  		o.XErrorCode = hdrXErrorCode
   106  	}
   107  
   108  	o.Payload = new(models.Error)
   109  
   110  	// response payload
   111  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   112  		return err
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  /*AddCommentToTaskBody A comment to create
   119  //
   120  // These values can have github flavored markdown.
   121  //
   122  swagger:model AddCommentToTaskBody
   123  */
   124  type AddCommentToTaskBody struct {
   125  
   126  	// content
   127  	// Required: true
   128  	Content *string `json:"content"`
   129  
   130  	// user Id
   131  	// Required: true
   132  	UserID *int64 `json:"userId"`
   133  }
   134  
   135  // Validate validates this add comment to task body
   136  func (o *AddCommentToTaskBody) Validate(formats strfmt.Registry) error {
   137  	var res []error
   138  
   139  	if err := o.validateContent(formats); err != nil {
   140  		res = append(res, err)
   141  	}
   142  
   143  	if err := o.validateUserID(formats); err != nil {
   144  		res = append(res, err)
   145  	}
   146  
   147  	if len(res) > 0 {
   148  		return errors.CompositeValidationError(res...)
   149  	}
   150  	return nil
   151  }
   152  
   153  func (o *AddCommentToTaskBody) validateContent(formats strfmt.Registry) error {
   154  
   155  	if err := validate.Required("body"+"."+"content", "body", o.Content); err != nil {
   156  		return err
   157  	}
   158  
   159  	return nil
   160  }
   161  
   162  func (o *AddCommentToTaskBody) validateUserID(formats strfmt.Registry) error {
   163  
   164  	if err := validate.Required("body"+"."+"userId", "body", o.UserID); err != nil {
   165  		return err
   166  	}
   167  
   168  	return nil
   169  }
   170  
   171  // ContextValidate validates this add comment to task body based on context it is used
   172  func (o *AddCommentToTaskBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   173  	return nil
   174  }
   175  
   176  // MarshalBinary interface implementation
   177  func (o *AddCommentToTaskBody) MarshalBinary() ([]byte, error) {
   178  	if o == nil {
   179  		return nil, nil
   180  	}
   181  	return swag.WriteJSON(o)
   182  }
   183  
   184  // UnmarshalBinary interface implementation
   185  func (o *AddCommentToTaskBody) UnmarshalBinary(b []byte) error {
   186  	var res AddCommentToTaskBody
   187  	if err := swag.ReadJSON(b, &res); err != nil {
   188  		return err
   189  	}
   190  	*o = res
   191  	return nil
   192  }