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