github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/task-tracker/client/tasks/list_tasks_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  	"encoding/json"
    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  
    18  	"github.com/thetreep/go-swagger/examples/task-tracker/models"
    19  )
    20  
    21  // ListTasksReader is a Reader for the ListTasks structure.
    22  type ListTasksReader struct {
    23  	formats strfmt.Registry
    24  }
    25  
    26  // ReadResponse reads a server response into the received o.
    27  func (o *ListTasksReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
    28  	switch response.Code() {
    29  	case 200:
    30  		result := NewListTasksOK()
    31  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    32  			return nil, err
    33  		}
    34  		return result, nil
    35  	case 422:
    36  		result := NewListTasksUnprocessableEntity()
    37  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    38  			return nil, err
    39  		}
    40  		return nil, result
    41  	default:
    42  		result := NewListTasksDefault(response.Code())
    43  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    44  			return nil, err
    45  		}
    46  		if response.Code()/100 == 2 {
    47  			return result, nil
    48  		}
    49  		return nil, result
    50  	}
    51  }
    52  
    53  // NewListTasksOK creates a ListTasksOK with default headers values
    54  func NewListTasksOK() *ListTasksOK {
    55  	return &ListTasksOK{}
    56  }
    57  
    58  /*
    59  ListTasksOK describes a response with status code 200, with default header values.
    60  
    61  Successful response
    62  */
    63  type ListTasksOK struct {
    64  
    65  	/* the last task id known to the application
    66  
    67  	   Format: int64
    68  	*/
    69  	XLastTaskID int64
    70  
    71  	Payload []*models.TaskCard
    72  }
    73  
    74  // IsSuccess returns true when this list tasks o k response has a 2xx status code
    75  func (o *ListTasksOK) IsSuccess() bool {
    76  	return true
    77  }
    78  
    79  // IsRedirect returns true when this list tasks o k response has a 3xx status code
    80  func (o *ListTasksOK) IsRedirect() bool {
    81  	return false
    82  }
    83  
    84  // IsClientError returns true when this list tasks o k response has a 4xx status code
    85  func (o *ListTasksOK) IsClientError() bool {
    86  	return false
    87  }
    88  
    89  // IsServerError returns true when this list tasks o k response has a 5xx status code
    90  func (o *ListTasksOK) IsServerError() bool {
    91  	return false
    92  }
    93  
    94  // IsCode returns true when this list tasks o k response a status code equal to that given
    95  func (o *ListTasksOK) IsCode(code int) bool {
    96  	return code == 200
    97  }
    98  
    99  // Code gets the status code for the list tasks o k response
   100  func (o *ListTasksOK) Code() int {
   101  	return 200
   102  }
   103  
   104  func (o *ListTasksOK) Error() string {
   105  	payload, _ := json.Marshal(o.Payload)
   106  	return fmt.Sprintf("[GET /tasks][%d] listTasksOK %s", 200, payload)
   107  }
   108  
   109  func (o *ListTasksOK) String() string {
   110  	payload, _ := json.Marshal(o.Payload)
   111  	return fmt.Sprintf("[GET /tasks][%d] listTasksOK %s", 200, payload)
   112  }
   113  
   114  func (o *ListTasksOK) GetPayload() []*models.TaskCard {
   115  	return o.Payload
   116  }
   117  
   118  func (o *ListTasksOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   119  
   120  	// hydrates response header X-Last-Task-Id
   121  	hdrXLastTaskID := response.GetHeader("X-Last-Task-Id")
   122  
   123  	if hdrXLastTaskID != "" {
   124  		valxLastTaskId, err := swag.ConvertInt64(hdrXLastTaskID)
   125  		if err != nil {
   126  			return errors.InvalidType("X-Last-Task-Id", "header", "int64", hdrXLastTaskID)
   127  		}
   128  		o.XLastTaskID = valxLastTaskId
   129  	}
   130  
   131  	// response payload
   132  	if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
   133  		return err
   134  	}
   135  
   136  	return nil
   137  }
   138  
   139  // NewListTasksUnprocessableEntity creates a ListTasksUnprocessableEntity with default headers values
   140  func NewListTasksUnprocessableEntity() *ListTasksUnprocessableEntity {
   141  	return &ListTasksUnprocessableEntity{}
   142  }
   143  
   144  /*
   145  ListTasksUnprocessableEntity describes a response with status code 422, with default header values.
   146  
   147  Validation error
   148  */
   149  type ListTasksUnprocessableEntity struct {
   150  	Payload *models.ValidationError
   151  }
   152  
   153  // IsSuccess returns true when this list tasks unprocessable entity response has a 2xx status code
   154  func (o *ListTasksUnprocessableEntity) IsSuccess() bool {
   155  	return false
   156  }
   157  
   158  // IsRedirect returns true when this list tasks unprocessable entity response has a 3xx status code
   159  func (o *ListTasksUnprocessableEntity) IsRedirect() bool {
   160  	return false
   161  }
   162  
   163  // IsClientError returns true when this list tasks unprocessable entity response has a 4xx status code
   164  func (o *ListTasksUnprocessableEntity) IsClientError() bool {
   165  	return true
   166  }
   167  
   168  // IsServerError returns true when this list tasks unprocessable entity response has a 5xx status code
   169  func (o *ListTasksUnprocessableEntity) IsServerError() bool {
   170  	return false
   171  }
   172  
   173  // IsCode returns true when this list tasks unprocessable entity response a status code equal to that given
   174  func (o *ListTasksUnprocessableEntity) IsCode(code int) bool {
   175  	return code == 422
   176  }
   177  
   178  // Code gets the status code for the list tasks unprocessable entity response
   179  func (o *ListTasksUnprocessableEntity) Code() int {
   180  	return 422
   181  }
   182  
   183  func (o *ListTasksUnprocessableEntity) Error() string {
   184  	payload, _ := json.Marshal(o.Payload)
   185  	return fmt.Sprintf("[GET /tasks][%d] listTasksUnprocessableEntity %s", 422, payload)
   186  }
   187  
   188  func (o *ListTasksUnprocessableEntity) String() string {
   189  	payload, _ := json.Marshal(o.Payload)
   190  	return fmt.Sprintf("[GET /tasks][%d] listTasksUnprocessableEntity %s", 422, payload)
   191  }
   192  
   193  func (o *ListTasksUnprocessableEntity) GetPayload() *models.ValidationError {
   194  	return o.Payload
   195  }
   196  
   197  func (o *ListTasksUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   198  
   199  	o.Payload = new(models.ValidationError)
   200  
   201  	// response payload
   202  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   203  		return err
   204  	}
   205  
   206  	return nil
   207  }
   208  
   209  // NewListTasksDefault creates a ListTasksDefault with default headers values
   210  func NewListTasksDefault(code int) *ListTasksDefault {
   211  	return &ListTasksDefault{
   212  		_statusCode: code,
   213  	}
   214  }
   215  
   216  /*
   217  ListTasksDefault describes a response with status code -1, with default header values.
   218  
   219  Error response
   220  */
   221  type ListTasksDefault struct {
   222  	_statusCode int
   223  	XErrorCode  string
   224  
   225  	Payload *models.Error
   226  }
   227  
   228  // IsSuccess returns true when this list tasks default response has a 2xx status code
   229  func (o *ListTasksDefault) IsSuccess() bool {
   230  	return o._statusCode/100 == 2
   231  }
   232  
   233  // IsRedirect returns true when this list tasks default response has a 3xx status code
   234  func (o *ListTasksDefault) IsRedirect() bool {
   235  	return o._statusCode/100 == 3
   236  }
   237  
   238  // IsClientError returns true when this list tasks default response has a 4xx status code
   239  func (o *ListTasksDefault) IsClientError() bool {
   240  	return o._statusCode/100 == 4
   241  }
   242  
   243  // IsServerError returns true when this list tasks default response has a 5xx status code
   244  func (o *ListTasksDefault) IsServerError() bool {
   245  	return o._statusCode/100 == 5
   246  }
   247  
   248  // IsCode returns true when this list tasks default response a status code equal to that given
   249  func (o *ListTasksDefault) IsCode(code int) bool {
   250  	return o._statusCode == code
   251  }
   252  
   253  // Code gets the status code for the list tasks default response
   254  func (o *ListTasksDefault) Code() int {
   255  	return o._statusCode
   256  }
   257  
   258  func (o *ListTasksDefault) Error() string {
   259  	payload, _ := json.Marshal(o.Payload)
   260  	return fmt.Sprintf("[GET /tasks][%d] listTasks default %s", o._statusCode, payload)
   261  }
   262  
   263  func (o *ListTasksDefault) String() string {
   264  	payload, _ := json.Marshal(o.Payload)
   265  	return fmt.Sprintf("[GET /tasks][%d] listTasks default %s", o._statusCode, payload)
   266  }
   267  
   268  func (o *ListTasksDefault) GetPayload() *models.Error {
   269  	return o.Payload
   270  }
   271  
   272  func (o *ListTasksDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   273  
   274  	// hydrates response header X-Error-Code
   275  	hdrXErrorCode := response.GetHeader("X-Error-Code")
   276  
   277  	if hdrXErrorCode != "" {
   278  		o.XErrorCode = hdrXErrorCode
   279  	}
   280  
   281  	o.Payload = new(models.Error)
   282  
   283  	// response payload
   284  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   285  		return err
   286  	}
   287  
   288  	return nil
   289  }