コード例 #1
0
// ReadFrom uses io.Copy with the BoduWriter if available after writing headers and checking that the writer is set
func (frw *FlexibleResponseWriter) ReadFrom(r io.Reader) (n int64, err error) {
	if !frw.wroteHeader {
		frw.WriteHeader(frw.Code)
	}

	if frw.BodyWriter == nil {
		return 0, utils.NewErrorWithStack("The body is not initialized, writes are not accepted.")
	}
	return io.Copy(frw.BodyWriter, r)
}
コード例 #2
0
// Write checks if a writer is initialized. If there is a body writer, it passes
// the arguments to it. If there isn't one, it fails.
func (frw *FlexibleResponseWriter) Write(buf []byte) (int, error) {
	if !frw.wroteHeader {
		frw.WriteHeader(frw.Code)
	}

	if frw.BodyWriter == nil {
		return 0, utils.NewErrorWithStack("The body is not initialized, writes are not accepted.")
	}
	return frw.BodyWriter.Write(buf)
}