github.com/emreu/go-swagger@v0.22.1/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  	"fmt"
    10  	"io"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/runtime"
    14  	"github.com/go-openapi/swag"
    15  	"github.com/go-openapi/validate"
    16  
    17  	strfmt "github.com/go-openapi/strfmt"
    18  
    19  	models "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  /*AddCommentToTaskCreated handles this case 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 handles this case with default header values.
    77  
    78  Error response
    79  */
    80  type AddCommentToTaskDefault struct {
    81  	_statusCode int
    82  
    83  	XErrorCode string
    84  
    85  	Payload *models.Error
    86  }
    87  
    88  // Code gets the status code for the add comment to task default response
    89  func (o *AddCommentToTaskDefault) Code() int {
    90  	return o._statusCode
    91  }
    92  
    93  func (o *AddCommentToTaskDefault) Error() string {
    94  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTask default  %+v", o._statusCode, o.Payload)
    95  }
    96  
    97  func (o *AddCommentToTaskDefault) GetPayload() *models.Error {
    98  	return o.Payload
    99  }
   100  
   101  func (o *AddCommentToTaskDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   102  
   103  	// response header X-Error-Code
   104  	o.XErrorCode = response.GetHeader("X-Error-Code")
   105  
   106  	o.Payload = new(models.Error)
   107  
   108  	// response payload
   109  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   110  		return err
   111  	}
   112  
   113  	return nil
   114  }
   115  
   116  /*AddCommentToTaskBody A comment to create
   117  //
   118  // These values can have github flavored markdown.
   119  //
   120  swagger:model AddCommentToTaskBody
   121  */
   122  type AddCommentToTaskBody struct {
   123  
   124  	// content
   125  	// Required: true
   126  	Content *string `json:"content"`
   127  
   128  	// user Id
   129  	// Required: true
   130  	UserID *int64 `json:"userId"`
   131  }
   132  
   133  // Validate validates this add comment to task body
   134  func (o *AddCommentToTaskBody) Validate(formats strfmt.Registry) error {
   135  	var res []error
   136  
   137  	if err := o.validateContent(formats); err != nil {
   138  		res = append(res, err)
   139  	}
   140  
   141  	if err := o.validateUserID(formats); err != nil {
   142  		res = append(res, err)
   143  	}
   144  
   145  	if len(res) > 0 {
   146  		return errors.CompositeValidationError(res...)
   147  	}
   148  	return nil
   149  }
   150  
   151  func (o *AddCommentToTaskBody) validateContent(formats strfmt.Registry) error {
   152  
   153  	if err := validate.Required("body"+"."+"content", "body", o.Content); err != nil {
   154  		return err
   155  	}
   156  
   157  	return nil
   158  }
   159  
   160  func (o *AddCommentToTaskBody) validateUserID(formats strfmt.Registry) error {
   161  
   162  	if err := validate.Required("body"+"."+"userId", "body", o.UserID); err != nil {
   163  		return err
   164  	}
   165  
   166  	return nil
   167  }
   168  
   169  // MarshalBinary interface implementation
   170  func (o *AddCommentToTaskBody) MarshalBinary() ([]byte, error) {
   171  	if o == nil {
   172  		return nil, nil
   173  	}
   174  	return swag.WriteJSON(o)
   175  }
   176  
   177  // UnmarshalBinary interface implementation
   178  func (o *AddCommentToTaskBody) UnmarshalBinary(b []byte) error {
   179  	var res AddCommentToTaskBody
   180  	if err := swag.ReadJSON(b, &res); err != nil {
   181  		return err
   182  	}
   183  	*o = res
   184  	return nil
   185  }