github.com/ffalor/go-swagger@v0.0.0-20231011000038-9f25265ac351/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/runtime"
    15  	"github.com/go-openapi/strfmt"
    16  	"github.com/go-openapi/swag"
    17  	"github.com/go-openapi/validate"
    18  
    19  	"github.com/go-swagger/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  /*
    54  AddCommentToTaskCreated describes a response with status code 201, with default header values.
    55  
    56  Comment added
    57  */
    58  type AddCommentToTaskCreated struct {
    59  }
    60  
    61  // IsSuccess returns true when this add comment to task created response has a 2xx status code
    62  func (o *AddCommentToTaskCreated) IsSuccess() bool {
    63  	return true
    64  }
    65  
    66  // IsRedirect returns true when this add comment to task created response has a 3xx status code
    67  func (o *AddCommentToTaskCreated) IsRedirect() bool {
    68  	return false
    69  }
    70  
    71  // IsClientError returns true when this add comment to task created response has a 4xx status code
    72  func (o *AddCommentToTaskCreated) IsClientError() bool {
    73  	return false
    74  }
    75  
    76  // IsServerError returns true when this add comment to task created response has a 5xx status code
    77  func (o *AddCommentToTaskCreated) IsServerError() bool {
    78  	return false
    79  }
    80  
    81  // IsCode returns true when this add comment to task created response a status code equal to that given
    82  func (o *AddCommentToTaskCreated) IsCode(code int) bool {
    83  	return code == 201
    84  }
    85  
    86  // Code gets the status code for the add comment to task created response
    87  func (o *AddCommentToTaskCreated) Code() int {
    88  	return 201
    89  }
    90  
    91  func (o *AddCommentToTaskCreated) Error() string {
    92  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTaskCreated ", 201)
    93  }
    94  
    95  func (o *AddCommentToTaskCreated) String() string {
    96  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTaskCreated ", 201)
    97  }
    98  
    99  func (o *AddCommentToTaskCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   100  
   101  	return nil
   102  }
   103  
   104  // NewAddCommentToTaskDefault creates a AddCommentToTaskDefault with default headers values
   105  func NewAddCommentToTaskDefault(code int) *AddCommentToTaskDefault {
   106  	return &AddCommentToTaskDefault{
   107  		_statusCode: code,
   108  	}
   109  }
   110  
   111  /*
   112  AddCommentToTaskDefault describes a response with status code -1, with default header values.
   113  
   114  Error response
   115  */
   116  type AddCommentToTaskDefault struct {
   117  	_statusCode int
   118  	XErrorCode  string
   119  
   120  	Payload *models.Error
   121  }
   122  
   123  // IsSuccess returns true when this add comment to task default response has a 2xx status code
   124  func (o *AddCommentToTaskDefault) IsSuccess() bool {
   125  	return o._statusCode/100 == 2
   126  }
   127  
   128  // IsRedirect returns true when this add comment to task default response has a 3xx status code
   129  func (o *AddCommentToTaskDefault) IsRedirect() bool {
   130  	return o._statusCode/100 == 3
   131  }
   132  
   133  // IsClientError returns true when this add comment to task default response has a 4xx status code
   134  func (o *AddCommentToTaskDefault) IsClientError() bool {
   135  	return o._statusCode/100 == 4
   136  }
   137  
   138  // IsServerError returns true when this add comment to task default response has a 5xx status code
   139  func (o *AddCommentToTaskDefault) IsServerError() bool {
   140  	return o._statusCode/100 == 5
   141  }
   142  
   143  // IsCode returns true when this add comment to task default response a status code equal to that given
   144  func (o *AddCommentToTaskDefault) IsCode(code int) bool {
   145  	return o._statusCode == code
   146  }
   147  
   148  // Code gets the status code for the add comment to task default response
   149  func (o *AddCommentToTaskDefault) Code() int {
   150  	return o._statusCode
   151  }
   152  
   153  func (o *AddCommentToTaskDefault) Error() string {
   154  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTask default  %+v", o._statusCode, o.Payload)
   155  }
   156  
   157  func (o *AddCommentToTaskDefault) String() string {
   158  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTask default  %+v", o._statusCode, o.Payload)
   159  }
   160  
   161  func (o *AddCommentToTaskDefault) GetPayload() *models.Error {
   162  	return o.Payload
   163  }
   164  
   165  func (o *AddCommentToTaskDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   166  
   167  	// hydrates response header X-Error-Code
   168  	hdrXErrorCode := response.GetHeader("X-Error-Code")
   169  
   170  	if hdrXErrorCode != "" {
   171  		o.XErrorCode = hdrXErrorCode
   172  	}
   173  
   174  	o.Payload = new(models.Error)
   175  
   176  	// response payload
   177  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   178  		return err
   179  	}
   180  
   181  	return nil
   182  }
   183  
   184  /*
   185  AddCommentToTaskBody A comment to create
   186  //
   187  // These values can have github flavored markdown.
   188  //
   189  swagger:model AddCommentToTaskBody
   190  */
   191  type AddCommentToTaskBody struct {
   192  
   193  	// content
   194  	// Required: true
   195  	Content *string `json:"content"`
   196  
   197  	// user Id
   198  	// Required: true
   199  	UserID *int64 `json:"userId"`
   200  }
   201  
   202  // Validate validates this add comment to task body
   203  func (o *AddCommentToTaskBody) Validate(formats strfmt.Registry) error {
   204  	var res []error
   205  
   206  	if err := o.validateContent(formats); err != nil {
   207  		res = append(res, err)
   208  	}
   209  
   210  	if err := o.validateUserID(formats); err != nil {
   211  		res = append(res, err)
   212  	}
   213  
   214  	if len(res) > 0 {
   215  		return errors.CompositeValidationError(res...)
   216  	}
   217  	return nil
   218  }
   219  
   220  func (o *AddCommentToTaskBody) validateContent(formats strfmt.Registry) error {
   221  
   222  	if err := validate.Required("body"+"."+"content", "body", o.Content); err != nil {
   223  		return err
   224  	}
   225  
   226  	return nil
   227  }
   228  
   229  func (o *AddCommentToTaskBody) validateUserID(formats strfmt.Registry) error {
   230  
   231  	if err := validate.Required("body"+"."+"userId", "body", o.UserID); err != nil {
   232  		return err
   233  	}
   234  
   235  	return nil
   236  }
   237  
   238  // ContextValidate validates this add comment to task body based on context it is used
   239  func (o *AddCommentToTaskBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   240  	return nil
   241  }
   242  
   243  // MarshalBinary interface implementation
   244  func (o *AddCommentToTaskBody) MarshalBinary() ([]byte, error) {
   245  	if o == nil {
   246  		return nil, nil
   247  	}
   248  	return swag.WriteJSON(o)
   249  }
   250  
   251  // UnmarshalBinary interface implementation
   252  func (o *AddCommentToTaskBody) UnmarshalBinary(b []byte) error {
   253  	var res AddCommentToTaskBody
   254  	if err := swag.ReadJSON(b, &res); err != nil {
   255  		return err
   256  	}
   257  	*o = res
   258  	return nil
   259  }