github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/todo-list/client/todos/add_one_responses.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package todos
     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  	"encoding/json"
    10  	"fmt"
    11  	"io"
    12  
    13  	"github.com/go-openapi/runtime"
    14  	"github.com/go-openapi/strfmt"
    15  
    16  	"github.com/thetreep/go-swagger/examples/todo-list/models"
    17  )
    18  
    19  // AddOneReader is a Reader for the AddOne structure.
    20  type AddOneReader struct {
    21  	formats strfmt.Registry
    22  }
    23  
    24  // ReadResponse reads a server response into the received o.
    25  func (o *AddOneReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
    26  	switch response.Code() {
    27  	case 201:
    28  		result := NewAddOneCreated()
    29  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    30  			return nil, err
    31  		}
    32  		return result, nil
    33  	default:
    34  		result := NewAddOneDefault(response.Code())
    35  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    36  			return nil, err
    37  		}
    38  		if response.Code()/100 == 2 {
    39  			return result, nil
    40  		}
    41  		return nil, result
    42  	}
    43  }
    44  
    45  // NewAddOneCreated creates a AddOneCreated with default headers values
    46  func NewAddOneCreated() *AddOneCreated {
    47  	return &AddOneCreated{}
    48  }
    49  
    50  /*
    51  AddOneCreated describes a response with status code 201, with default header values.
    52  
    53  Created
    54  */
    55  type AddOneCreated struct {
    56  	Payload *models.Item
    57  }
    58  
    59  // IsSuccess returns true when this add one created response has a 2xx status code
    60  func (o *AddOneCreated) IsSuccess() bool {
    61  	return true
    62  }
    63  
    64  // IsRedirect returns true when this add one created response has a 3xx status code
    65  func (o *AddOneCreated) IsRedirect() bool {
    66  	return false
    67  }
    68  
    69  // IsClientError returns true when this add one created response has a 4xx status code
    70  func (o *AddOneCreated) IsClientError() bool {
    71  	return false
    72  }
    73  
    74  // IsServerError returns true when this add one created response has a 5xx status code
    75  func (o *AddOneCreated) IsServerError() bool {
    76  	return false
    77  }
    78  
    79  // IsCode returns true when this add one created response a status code equal to that given
    80  func (o *AddOneCreated) IsCode(code int) bool {
    81  	return code == 201
    82  }
    83  
    84  // Code gets the status code for the add one created response
    85  func (o *AddOneCreated) Code() int {
    86  	return 201
    87  }
    88  
    89  func (o *AddOneCreated) Error() string {
    90  	payload, _ := json.Marshal(o.Payload)
    91  	return fmt.Sprintf("[POST /][%d] addOneCreated %s", 201, payload)
    92  }
    93  
    94  func (o *AddOneCreated) String() string {
    95  	payload, _ := json.Marshal(o.Payload)
    96  	return fmt.Sprintf("[POST /][%d] addOneCreated %s", 201, payload)
    97  }
    98  
    99  func (o *AddOneCreated) GetPayload() *models.Item {
   100  	return o.Payload
   101  }
   102  
   103  func (o *AddOneCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   104  
   105  	o.Payload = new(models.Item)
   106  
   107  	// response payload
   108  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   109  		return err
   110  	}
   111  
   112  	return nil
   113  }
   114  
   115  // NewAddOneDefault creates a AddOneDefault with default headers values
   116  func NewAddOneDefault(code int) *AddOneDefault {
   117  	return &AddOneDefault{
   118  		_statusCode: code,
   119  	}
   120  }
   121  
   122  /*
   123  AddOneDefault describes a response with status code -1, with default header values.
   124  
   125  error
   126  */
   127  type AddOneDefault struct {
   128  	_statusCode int
   129  
   130  	Payload *models.Error
   131  }
   132  
   133  // IsSuccess returns true when this add one default response has a 2xx status code
   134  func (o *AddOneDefault) IsSuccess() bool {
   135  	return o._statusCode/100 == 2
   136  }
   137  
   138  // IsRedirect returns true when this add one default response has a 3xx status code
   139  func (o *AddOneDefault) IsRedirect() bool {
   140  	return o._statusCode/100 == 3
   141  }
   142  
   143  // IsClientError returns true when this add one default response has a 4xx status code
   144  func (o *AddOneDefault) IsClientError() bool {
   145  	return o._statusCode/100 == 4
   146  }
   147  
   148  // IsServerError returns true when this add one default response has a 5xx status code
   149  func (o *AddOneDefault) IsServerError() bool {
   150  	return o._statusCode/100 == 5
   151  }
   152  
   153  // IsCode returns true when this add one default response a status code equal to that given
   154  func (o *AddOneDefault) IsCode(code int) bool {
   155  	return o._statusCode == code
   156  }
   157  
   158  // Code gets the status code for the add one default response
   159  func (o *AddOneDefault) Code() int {
   160  	return o._statusCode
   161  }
   162  
   163  func (o *AddOneDefault) Error() string {
   164  	payload, _ := json.Marshal(o.Payload)
   165  	return fmt.Sprintf("[POST /][%d] addOne default %s", o._statusCode, payload)
   166  }
   167  
   168  func (o *AddOneDefault) String() string {
   169  	payload, _ := json.Marshal(o.Payload)
   170  	return fmt.Sprintf("[POST /][%d] addOne default %s", o._statusCode, payload)
   171  }
   172  
   173  func (o *AddOneDefault) GetPayload() *models.Error {
   174  	return o.Payload
   175  }
   176  
   177  func (o *AddOneDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   178  
   179  	o.Payload = new(models.Error)
   180  
   181  	// response payload
   182  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   183  		return err
   184  	}
   185  
   186  	return nil
   187  }