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