github.com/djarvur/go-swagger@v0.18.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  	"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  
    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  
    38  	default:
    39  		result := NewAddCommentToTaskDefault(response.Code())
    40  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    41  			return nil, err
    42  		}
    43  		if response.Code()/100 == 2 {
    44  			return result, nil
    45  		}
    46  		return nil, result
    47  	}
    48  }
    49  
    50  // NewAddCommentToTaskCreated creates a AddCommentToTaskCreated with default headers values
    51  func NewAddCommentToTaskCreated() *AddCommentToTaskCreated {
    52  	return &AddCommentToTaskCreated{}
    53  }
    54  
    55  /*AddCommentToTaskCreated handles this case with default header values.
    56  
    57  Comment added
    58  */
    59  type AddCommentToTaskCreated struct {
    60  }
    61  
    62  func (o *AddCommentToTaskCreated) Error() string {
    63  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTaskCreated ", 201)
    64  }
    65  
    66  func (o *AddCommentToTaskCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    67  
    68  	return nil
    69  }
    70  
    71  // NewAddCommentToTaskDefault creates a AddCommentToTaskDefault with default headers values
    72  func NewAddCommentToTaskDefault(code int) *AddCommentToTaskDefault {
    73  	return &AddCommentToTaskDefault{
    74  		_statusCode: code,
    75  	}
    76  }
    77  
    78  /*AddCommentToTaskDefault handles this case with default header values.
    79  
    80  Error response
    81  */
    82  type AddCommentToTaskDefault struct {
    83  	_statusCode int
    84  
    85  	XErrorCode string
    86  
    87  	Payload *models.Error
    88  }
    89  
    90  // Code gets the status code for the add comment to task default response
    91  func (o *AddCommentToTaskDefault) Code() int {
    92  	return o._statusCode
    93  }
    94  
    95  func (o *AddCommentToTaskDefault) Error() string {
    96  	return fmt.Sprintf("[POST /tasks/{id}/comments][%d] addCommentToTask default  %+v", o._statusCode, o.Payload)
    97  }
    98  
    99  func (o *AddCommentToTaskDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   100  
   101  	// response header X-Error-Code
   102  	o.XErrorCode = response.GetHeader("X-Error-Code")
   103  
   104  	o.Payload = new(models.Error)
   105  
   106  	// response payload
   107  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   108  		return err
   109  	}
   110  
   111  	return nil
   112  }
   113  
   114  /*AddCommentToTaskBody A comment to create
   115  //
   116  // These values can have github flavored markdown.
   117  //
   118  swagger:model AddCommentToTaskBody
   119  */
   120  type AddCommentToTaskBody struct {
   121  
   122  	// content
   123  	// Required: true
   124  	Content *string `json:"content"`
   125  
   126  	// user Id
   127  	// Required: true
   128  	UserID *int64 `json:"userId"`
   129  }
   130  
   131  // Validate validates this add comment to task body
   132  func (o *AddCommentToTaskBody) Validate(formats strfmt.Registry) error {
   133  	var res []error
   134  
   135  	if err := o.validateContent(formats); err != nil {
   136  		res = append(res, err)
   137  	}
   138  
   139  	if err := o.validateUserID(formats); err != nil {
   140  		res = append(res, err)
   141  	}
   142  
   143  	if len(res) > 0 {
   144  		return errors.CompositeValidationError(res...)
   145  	}
   146  	return nil
   147  }
   148  
   149  func (o *AddCommentToTaskBody) validateContent(formats strfmt.Registry) error {
   150  
   151  	if err := validate.Required("body"+"."+"content", "body", o.Content); err != nil {
   152  		return err
   153  	}
   154  
   155  	return nil
   156  }
   157  
   158  func (o *AddCommentToTaskBody) validateUserID(formats strfmt.Registry) error {
   159  
   160  	if err := validate.Required("body"+"."+"userId", "body", o.UserID); err != nil {
   161  		return err
   162  	}
   163  
   164  	return nil
   165  }
   166  
   167  // MarshalBinary interface implementation
   168  func (o *AddCommentToTaskBody) MarshalBinary() ([]byte, error) {
   169  	if o == nil {
   170  		return nil, nil
   171  	}
   172  	return swag.WriteJSON(o)
   173  }
   174  
   175  // UnmarshalBinary interface implementation
   176  func (o *AddCommentToTaskBody) UnmarshalBinary(b []byte) error {
   177  	var res AddCommentToTaskBody
   178  	if err := swag.ReadJSON(b, &res); err != nil {
   179  		return err
   180  	}
   181  	*o = res
   182  	return nil
   183  }