1
0
Fork 0
mirror of https://github.com/Luzifer/expose.git synced 2024-11-14 00:52:49 +00:00
expose/vendor/github.com/Luzifer/go_helpers/accessLogger/accessLogger.go
Knut Ahlers 360c8ec055
Switch to dep for vendoring
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-09-17 21:32:52 +02:00

37 lines
721 B
Go

package accessLogger
import (
"fmt"
"net/http"
"strconv"
)
type AccessLogResponseWriter struct {
StatusCode int
Size int
http.ResponseWriter
}
func New(res http.ResponseWriter) *AccessLogResponseWriter {
return &AccessLogResponseWriter{
StatusCode: 200,
Size: 0,
ResponseWriter: res,
}
}
func (a *AccessLogResponseWriter) Write(out []byte) (int, error) {
s, err := a.ResponseWriter.Write(out)
a.Size += s
return s, err
}
func (a *AccessLogResponseWriter) WriteHeader(code int) {
a.StatusCode = code
a.ResponseWriter.WriteHeader(code)
}
func (a *AccessLogResponseWriter) HTTPResponseType() string {
return fmt.Sprintf("%cxx", strconv.FormatInt(int64(a.StatusCode), 10)[0])
}