github.com/emreu/go-swagger@v0.22.1/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  	"fmt"
    10  	"io"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/runtime"
    14  	"github.com/go-openapi/swag"
    15  
    16  	strfmt "github.com/go-openapi/strfmt"
    17  
    18  	models "github.com/go-swagger/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  /*ListTasksOK handles this case with default header values.
    59  
    60  Successful response
    61  */
    62  type ListTasksOK struct {
    63  	/*the last task id known to the application
    64  	 */
    65  	XLastTaskID int64
    66  
    67  	Payload []*models.TaskCard
    68  }
    69  
    70  func (o *ListTasksOK) Error() string {
    71  	return fmt.Sprintf("[GET /tasks][%d] listTasksOK  %+v", 200, o.Payload)
    72  }
    73  
    74  func (o *ListTasksOK) GetPayload() []*models.TaskCard {
    75  	return o.Payload
    76  }
    77  
    78  func (o *ListTasksOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    79  
    80  	// response header X-Last-Task-Id
    81  	xLastTaskId, err := swag.ConvertInt64(response.GetHeader("X-Last-Task-Id"))
    82  	if err != nil {
    83  		return errors.InvalidType("X-Last-Task-Id", "header", "int64", response.GetHeader("X-Last-Task-Id"))
    84  	}
    85  	o.XLastTaskID = xLastTaskId
    86  
    87  	// response payload
    88  	if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
    89  		return err
    90  	}
    91  
    92  	return nil
    93  }
    94  
    95  // NewListTasksUnprocessableEntity creates a ListTasksUnprocessableEntity with default headers values
    96  func NewListTasksUnprocessableEntity() *ListTasksUnprocessableEntity {
    97  	return &ListTasksUnprocessableEntity{}
    98  }
    99  
   100  /*ListTasksUnprocessableEntity handles this case with default header values.
   101  
   102  Validation error
   103  */
   104  type ListTasksUnprocessableEntity struct {
   105  	Payload *models.ValidationError
   106  }
   107  
   108  func (o *ListTasksUnprocessableEntity) Error() string {
   109  	return fmt.Sprintf("[GET /tasks][%d] listTasksUnprocessableEntity  %+v", 422, o.Payload)
   110  }
   111  
   112  func (o *ListTasksUnprocessableEntity) GetPayload() *models.ValidationError {
   113  	return o.Payload
   114  }
   115  
   116  func (o *ListTasksUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   117  
   118  	o.Payload = new(models.ValidationError)
   119  
   120  	// response payload
   121  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   122  		return err
   123  	}
   124  
   125  	return nil
   126  }
   127  
   128  // NewListTasksDefault creates a ListTasksDefault with default headers values
   129  func NewListTasksDefault(code int) *ListTasksDefault {
   130  	return &ListTasksDefault{
   131  		_statusCode: code,
   132  	}
   133  }
   134  
   135  /*ListTasksDefault handles this case with default header values.
   136  
   137  Error response
   138  */
   139  type ListTasksDefault struct {
   140  	_statusCode int
   141  
   142  	XErrorCode string
   143  
   144  	Payload *models.Error
   145  }
   146  
   147  // Code gets the status code for the list tasks default response
   148  func (o *ListTasksDefault) Code() int {
   149  	return o._statusCode
   150  }
   151  
   152  func (o *ListTasksDefault) Error() string {
   153  	return fmt.Sprintf("[GET /tasks][%d] listTasks default  %+v", o._statusCode, o.Payload)
   154  }
   155  
   156  func (o *ListTasksDefault) GetPayload() *models.Error {
   157  	return o.Payload
   158  }
   159  
   160  func (o *ListTasksDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   161  
   162  	// response header X-Error-Code
   163  	o.XErrorCode = response.GetHeader("X-Error-Code")
   164  
   165  	o.Payload = new(models.Error)
   166  
   167  	// response payload
   168  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   169  		return err
   170  	}
   171  
   172  	return nil
   173  }