1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-03 22:52:19 +02:00
echo/response.go
Vishal Rana 73fa05f826 Added panic recover middleware
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-05-17 22:54:29 -07:00

52 lines
815 B
Go

package echo
import (
"log"
"net/http"
"github.com/labstack/gommon/color"
)
type (
Response struct {
Writer http.ResponseWriter
status int
size int64
committed bool
}
)
func (r *Response) Header() http.Header {
return r.Writer.Header()
}
func (r *Response) WriteHeader(code int) {
if r.committed {
// TODO: Warning
log.Printf("echo ⇒ %s", color.Yellow("response already committed"))
return
}
r.status = code
r.Writer.WriteHeader(code)
r.committed = true
}
func (r *Response) Write(b []byte) (n int, err error) {
n, err = r.Writer.Write(b)
r.size += int64(n)
return n, err
}
func (r *Response) Status() int {
return r.status
}
func (r *Response) Size() int64 {
return r.size
}
func (r *Response) reset(w http.ResponseWriter) {
r.Writer = w
r.committed = false
}