// WriteResponse to the client
func (o *GetInventoryOK) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	rw.WriteHeader(200)
	if err := producer.Produce(rw, o.Payload); err != nil {
		panic(err) // let the recovery middleware deal with this
	}

}
// WriteResponse to the client
func (o *FindReviewsForLearningResourceOK) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	rw.WriteHeader(200)
	if err := producer.Produce(rw, o.Payload); err != nil {
		panic(err) // let the recovery middleware deal with this
	}

}
Beispiel #3
0
func (o *FindDefault) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	rw.WriteHeader(500)
	if o.Payload != nil {
		if err := producer.Produce(rw, o.Payload); err != nil {
			panic(err) // let the recovery middleware deal with this
		}
	}
}
// WriteResponse to the client
func (o *GetTaskDetailsUnprocessableEntity) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	rw.WriteHeader(422)
	if o.Payload != nil {
		if err := producer.Produce(rw, o.Payload); err != nil {
			panic(err) // let the recovery middleware deal with this
		}
	}
}
// WriteResponse to the client
func (o *AddLearningResourceDefault) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	rw.WriteHeader(o._statusCode)
	if o.Payload != nil {
		if err := producer.Produce(rw, o.Payload); err != nil {
			panic(err) // let the recovery middleware deal with this
		}
	}
}
// WriteResponse to the client
func (o *DeleteEventInternalServerError) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	rw.WriteHeader(500)
	if o.Payload != nil {
		if err := producer.Produce(rw, o.Payload); err != nil {
			panic(err) // let the recovery middleware deal with this
		}
	}
}
// WriteResponse to the client
func (o *AddOneCreated) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	rw.WriteHeader(201)
	if o.Payload != nil {
		if err := producer.Produce(rw, o.Payload); err != nil {
			panic(err) // let the recovery middleware deal with this
		}
	}
}
// WriteResponse to the client
func (o *ListTasksOK) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	// response header X-Last-Task-Id
	rw.Header().Add("X-Last-Task-Id", fmt.Sprintf("%v", o.XLastTaskID))

	rw.WriteHeader(200)
	if err := producer.Produce(rw, o.Payload); err != nil {
		panic(err) // let the recovery middleware deal with this
	}

}
// WriteResponse to the client
func (o *LoginUserOK) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

	// response header X-Expires-After
	rw.Header().Add("X-Expires-After", fmt.Sprintf("%v", o.XExpiresAfter))

	// response header X-Rate-Limit
	rw.Header().Add("X-Rate-Limit", fmt.Sprintf("%v", o.XRateLimit))

	rw.WriteHeader(200)
	if err := producer.Produce(rw, o.Payload); err != nil {
		panic(err) // let the recovery middleware deal with this
	}

}
Beispiel #10
0
func (e *errorResp) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {
	for k, v := range e.headers {
		for _, val := range v {
			rw.Header().Add(k, val)
		}
	}
	if e.code > 0 {
		rw.WriteHeader(e.code)
	} else {
		rw.WriteHeader(http.StatusInternalServerError)
	}
	if err := producer.Produce(rw, e.response); err != nil {
		panic(err)
	}
}
Beispiel #11
0
// BuildHTTP creates a new http request based on the data from the params
func (r *request) BuildHTTP(producer httpkit.Producer, registry strfmt.Registry) (*http.Request, error) {
	// build the data
	if err := r.writer.WriteToRequest(r, registry); err != nil {
		return nil, err
	}

	// create http request
	path := r.pathPattern
	for k, v := range r.pathParams {
		path = strings.Replace(path, "{"+k+"}", v, -1)
	}

	var body io.ReadCloser
	var pr *io.PipeReader
	var pw *io.PipeWriter
	buf := bytes.NewBuffer(nil)
	body = ioutil.NopCloser(buf)
	if r.fileFields != nil {
		pr, pw = io.Pipe()
		body = pr
	}
	req, err := http.NewRequest(r.method, path, body)
	if err != nil {
		return nil, err
	}
	req.URL.RawQuery = r.query.Encode()
	req.Header = r.header

	// check if this is a form type request
	if len(r.formFields) > 0 || len(r.fileFields) > 0 {
		// check if this is multipart
		if len(r.fileFields) > 0 {
			mp := multipart.NewWriter(pw)
			req.Header.Set(httpkit.HeaderContentType, mp.FormDataContentType())

			go func() {
				defer func() {
					mp.Close()
					pw.Close()
				}()

				for fn, v := range r.formFields {
					if len(v) > 0 {
						if err := mp.WriteField(fn, v[0]); err != nil {
							pw.CloseWithError(err)
							log.Fatal(err)
						}
					}
				}

				for fn, f := range r.fileFields {
					wrtr, err := mp.CreateFormFile(fn, filepath.Base(f.Name()))
					if err != nil {
						pw.CloseWithError(err)
						log.Fatal(err)
					}
					defer func() {
						for _, ff := range r.fileFields {
							ff.Close()
						}

					}()
					if _, err := io.Copy(wrtr, f); err != nil {
						pw.CloseWithError(err)
						log.Fatal(err)
					}
				}

			}()
			return req, nil
		}
		buf.WriteString(r.formFields.Encode())
		return req, nil
	}

	// write the form values as body
	// if there is payload, use the producer to write the payload
	if r.payload != nil {
		if err := producer.Produce(buf, r.payload); err != nil {
			return nil, err
		}
	}
	return req, nil
}
Beispiel #12
0
// BuildHTTP creates a new http request based on the data from the params
func (r *request) BuildHTTP(producer httpkit.Producer, registry strfmt.Registry) (*http.Request, error) {
	// build the data
	if err := r.writer.WriteToRequest(r, registry); err != nil {
		return nil, err
	}

	// create http request
	path := r.pathPattern
	for k, v := range r.pathParams {
		path = strings.Replace(path, "{"+k+"}", v, -1)
	}

	// TODO: Support uploading huge bodies!
	// Not too excited about the buffer here, but it keeps me going for now
	body := bytes.NewBuffer(nil)
	req, err := http.NewRequest(r.method, path, body)
	if err != nil {
		return nil, err
	}
	req.URL.RawQuery = r.query.Encode()
	req.Header = r.header

	// check if this is a form type request
	if r.formFields != nil {
		// check if this is multipart
		if r.fileFields != nil {

			mp := multipart.NewWriter(body)
			defer mp.Close()
			req.Header.Set(httpkit.HeaderContentType, mp.FormDataContentType())

			for fn, v := range r.formFields {
				if len(v) > 0 {
					if err := mp.WriteField(fn, v[0]); err != nil {
						return nil, err
					}
				}
			}

			for fn, f := range r.fileFields {
				wrtr, err := mp.CreateFormFile(fn, filepath.Base(f.Name()))
				if err != nil {
					return nil, err
				}
				defer func() {
					for _, ff := range r.fileFields {
						ff.Close()
					}
				}()
				// TODO: Support uploading huge files!
				// Stop this copy insanity!
				if _, err := io.Copy(wrtr, f); err != nil {
					return nil, err
				}
			}

			return req, nil
		}
		body.WriteString(r.formFields.Encode())
		return req, nil
	}

	// write the form values as body
	// if there is payload, use the producer to write the payload
	if err := producer.Produce(body, r.payload); err != nil {
		return nil, err
	}
	return req, nil
}