github.com/ffalor/go-swagger@v0.0.0-20231011000038-9f25265ac351/examples/task-tracker/client/tasks/create_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/strfmt"
    15  
    16  	"github.com/go-swagger/go-swagger/examples/task-tracker/models"
    17  )
    18  
    19  // CreateTaskReader is a Reader for the CreateTask structure.
    20  type CreateTaskReader struct {
    21  	formats strfmt.Registry
    22  }
    23  
    24  // ReadResponse reads a server response into the received o.
    25  func (o *CreateTaskReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
    26  	switch response.Code() {
    27  	case 201:
    28  		result := NewCreateTaskCreated()
    29  		if err := result.readResponse(response, consumer, o.formats); err != nil {
    30  			return nil, err
    31  		}
    32  		return result, nil
    33  	default:
    34  		result := NewCreateTaskDefault(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  // NewCreateTaskCreated creates a CreateTaskCreated with default headers values
    46  func NewCreateTaskCreated() *CreateTaskCreated {
    47  	return &CreateTaskCreated{}
    48  }
    49  
    50  /*
    51  CreateTaskCreated describes a response with status code 201, with default header values.
    52  
    53  Task created
    54  */
    55  type CreateTaskCreated struct {
    56  
    57  	/* URL to the newly added Task
    58  
    59  	   Format: uri
    60  	*/
    61  	Location strfmt.URI
    62  }
    63  
    64  // IsSuccess returns true when this create task created response has a 2xx status code
    65  func (o *CreateTaskCreated) IsSuccess() bool {
    66  	return true
    67  }
    68  
    69  // IsRedirect returns true when this create task created response has a 3xx status code
    70  func (o *CreateTaskCreated) IsRedirect() bool {
    71  	return false
    72  }
    73  
    74  // IsClientError returns true when this create task created response has a 4xx status code
    75  func (o *CreateTaskCreated) IsClientError() bool {
    76  	return false
    77  }
    78  
    79  // IsServerError returns true when this create task created response has a 5xx status code
    80  func (o *CreateTaskCreated) IsServerError() bool {
    81  	return false
    82  }
    83  
    84  // IsCode returns true when this create task created response a status code equal to that given
    85  func (o *CreateTaskCreated) IsCode(code int) bool {
    86  	return code == 201
    87  }
    88  
    89  // Code gets the status code for the create task created response
    90  func (o *CreateTaskCreated) Code() int {
    91  	return 201
    92  }
    93  
    94  func (o *CreateTaskCreated) Error() string {
    95  	return fmt.Sprintf("[POST /tasks][%d] createTaskCreated ", 201)
    96  }
    97  
    98  func (o *CreateTaskCreated) String() string {
    99  	return fmt.Sprintf("[POST /tasks][%d] createTaskCreated ", 201)
   100  }
   101  
   102  func (o *CreateTaskCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   103  
   104  	// hydrates response header Location
   105  	hdrLocation := response.GetHeader("Location")
   106  
   107  	if hdrLocation != "" {
   108  		vallocation, err := formats.Parse("uri", hdrLocation)
   109  		if err != nil {
   110  			return errors.InvalidType("Location", "header", "strfmt.URI", hdrLocation)
   111  		}
   112  		o.Location = *(vallocation.(*strfmt.URI))
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  // NewCreateTaskDefault creates a CreateTaskDefault with default headers values
   119  func NewCreateTaskDefault(code int) *CreateTaskDefault {
   120  	return &CreateTaskDefault{
   121  		_statusCode: code,
   122  	}
   123  }
   124  
   125  /*
   126  CreateTaskDefault describes a response with status code -1, with default header values.
   127  
   128  Error response
   129  */
   130  type CreateTaskDefault struct {
   131  	_statusCode int
   132  	XErrorCode  string
   133  
   134  	Payload *models.Error
   135  }
   136  
   137  // IsSuccess returns true when this create task default response has a 2xx status code
   138  func (o *CreateTaskDefault) IsSuccess() bool {
   139  	return o._statusCode/100 == 2
   140  }
   141  
   142  // IsRedirect returns true when this create task default response has a 3xx status code
   143  func (o *CreateTaskDefault) IsRedirect() bool {
   144  	return o._statusCode/100 == 3
   145  }
   146  
   147  // IsClientError returns true when this create task default response has a 4xx status code
   148  func (o *CreateTaskDefault) IsClientError() bool {
   149  	return o._statusCode/100 == 4
   150  }
   151  
   152  // IsServerError returns true when this create task default response has a 5xx status code
   153  func (o *CreateTaskDefault) IsServerError() bool {
   154  	return o._statusCode/100 == 5
   155  }
   156  
   157  // IsCode returns true when this create task default response a status code equal to that given
   158  func (o *CreateTaskDefault) IsCode(code int) bool {
   159  	return o._statusCode == code
   160  }
   161  
   162  // Code gets the status code for the create task default response
   163  func (o *CreateTaskDefault) Code() int {
   164  	return o._statusCode
   165  }
   166  
   167  func (o *CreateTaskDefault) Error() string {
   168  	return fmt.Sprintf("[POST /tasks][%d] createTask default  %+v", o._statusCode, o.Payload)
   169  }
   170  
   171  func (o *CreateTaskDefault) String() string {
   172  	return fmt.Sprintf("[POST /tasks][%d] createTask default  %+v", o._statusCode, o.Payload)
   173  }
   174  
   175  func (o *CreateTaskDefault) GetPayload() *models.Error {
   176  	return o.Payload
   177  }
   178  
   179  func (o *CreateTaskDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
   180  
   181  	// hydrates response header X-Error-Code
   182  	hdrXErrorCode := response.GetHeader("X-Error-Code")
   183  
   184  	if hdrXErrorCode != "" {
   185  		o.XErrorCode = hdrXErrorCode
   186  	}
   187  
   188  	o.Payload = new(models.Error)
   189  
   190  	// response payload
   191  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   192  		return err
   193  	}
   194  
   195  	return nil
   196  }