github.com/emreu/go-swagger@v0.22.1/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/runtime"
    13  
    14  	strfmt "github.com/go-openapi/strfmt"
    15  
    16  	models "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  /*CreateTaskCreated handles this case with default header values.
    51  
    52  Task created
    53  */
    54  type CreateTaskCreated struct {
    55  }
    56  
    57  func (o *CreateTaskCreated) Error() string {
    58  	return fmt.Sprintf("[POST /tasks][%d] createTaskCreated ", 201)
    59  }
    60  
    61  func (o *CreateTaskCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    62  
    63  	return nil
    64  }
    65  
    66  // NewCreateTaskDefault creates a CreateTaskDefault with default headers values
    67  func NewCreateTaskDefault(code int) *CreateTaskDefault {
    68  	return &CreateTaskDefault{
    69  		_statusCode: code,
    70  	}
    71  }
    72  
    73  /*CreateTaskDefault handles this case with default header values.
    74  
    75  Error response
    76  */
    77  type CreateTaskDefault struct {
    78  	_statusCode int
    79  
    80  	XErrorCode string
    81  
    82  	Payload *models.Error
    83  }
    84  
    85  // Code gets the status code for the create task default response
    86  func (o *CreateTaskDefault) Code() int {
    87  	return o._statusCode
    88  }
    89  
    90  func (o *CreateTaskDefault) Error() string {
    91  	return fmt.Sprintf("[POST /tasks][%d] createTask default  %+v", o._statusCode, o.Payload)
    92  }
    93  
    94  func (o *CreateTaskDefault) GetPayload() *models.Error {
    95  	return o.Payload
    96  }
    97  
    98  func (o *CreateTaskDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
    99  
   100  	// response header X-Error-Code
   101  	o.XErrorCode = response.GetHeader("X-Error-Code")
   102  
   103  	o.Payload = new(models.Error)
   104  
   105  	// response payload
   106  	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
   107  		return err
   108  	}
   109  
   110  	return nil
   111  }