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