github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/examples/task-tracker/restapi/operations/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 "net/http" 10 11 "github.com/go-openapi/runtime" 12 "github.com/go-openapi/strfmt" 13 14 "github.com/go-swagger/go-swagger/examples/task-tracker/models" 15 ) 16 17 // CreateTaskCreatedCode is the HTTP code returned for type CreateTaskCreated 18 const CreateTaskCreatedCode int = 201 19 20 /* 21 CreateTaskCreated Task created 22 23 swagger:response createTaskCreated 24 */ 25 type CreateTaskCreated struct { 26 /*URL to the newly added Task 27 28 */ 29 Location strfmt.URI `json:"Location"` 30 } 31 32 // NewCreateTaskCreated creates CreateTaskCreated with default headers values 33 func NewCreateTaskCreated() *CreateTaskCreated { 34 35 return &CreateTaskCreated{} 36 } 37 38 // WithLocation adds the location to the create task created response 39 func (o *CreateTaskCreated) WithLocation(location strfmt.URI) *CreateTaskCreated { 40 o.Location = location 41 return o 42 } 43 44 // SetLocation sets the location to the create task created response 45 func (o *CreateTaskCreated) SetLocation(location strfmt.URI) { 46 o.Location = location 47 } 48 49 // WriteResponse to the client 50 func (o *CreateTaskCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { 51 52 // response header Location 53 54 location := o.Location.String() 55 if location != "" { 56 rw.Header().Set("Location", location) 57 } 58 59 rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses 60 61 rw.WriteHeader(201) 62 } 63 64 /* 65 CreateTaskDefault Error response 66 67 swagger:response createTaskDefault 68 */ 69 type CreateTaskDefault struct { 70 _statusCode int 71 /* 72 73 */ 74 XErrorCode string `json:"X-Error-Code"` 75 76 /* 77 In: Body 78 */ 79 Payload *models.Error `json:"body,omitempty"` 80 } 81 82 // NewCreateTaskDefault creates CreateTaskDefault with default headers values 83 func NewCreateTaskDefault(code int) *CreateTaskDefault { 84 if code <= 0 { 85 code = 500 86 } 87 88 return &CreateTaskDefault{ 89 _statusCode: code, 90 } 91 } 92 93 // WithStatusCode adds the status to the create task default response 94 func (o *CreateTaskDefault) WithStatusCode(code int) *CreateTaskDefault { 95 o._statusCode = code 96 return o 97 } 98 99 // SetStatusCode sets the status to the create task default response 100 func (o *CreateTaskDefault) SetStatusCode(code int) { 101 o._statusCode = code 102 } 103 104 // WithXErrorCode adds the xErrorCode to the create task default response 105 func (o *CreateTaskDefault) WithXErrorCode(xErrorCode string) *CreateTaskDefault { 106 o.XErrorCode = xErrorCode 107 return o 108 } 109 110 // SetXErrorCode sets the xErrorCode to the create task default response 111 func (o *CreateTaskDefault) SetXErrorCode(xErrorCode string) { 112 o.XErrorCode = xErrorCode 113 } 114 115 // WithPayload adds the payload to the create task default response 116 func (o *CreateTaskDefault) WithPayload(payload *models.Error) *CreateTaskDefault { 117 o.Payload = payload 118 return o 119 } 120 121 // SetPayload sets the payload to the create task default response 122 func (o *CreateTaskDefault) SetPayload(payload *models.Error) { 123 o.Payload = payload 124 } 125 126 // WriteResponse to the client 127 func (o *CreateTaskDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { 128 129 // response header X-Error-Code 130 131 xErrorCode := o.XErrorCode 132 if xErrorCode != "" { 133 rw.Header().Set("X-Error-Code", xErrorCode) 134 } 135 136 rw.WriteHeader(o._statusCode) 137 if o.Payload != nil { 138 payload := o.Payload 139 if err := producer.Produce(rw, payload); err != nil { 140 panic(err) // let the recovery middleware deal with this 141 } 142 } 143 }