mirror of
https://github.com/Luzifer/ots.git
synced 2024-10-01 01:06:09 -04:00
5e3d84df9b
Signed-off-by: Knut Ahlers <knut@ahlers.me>
38 lines
721 B
Go
38 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("%sxx", strconv.FormatInt(int64(a.StatusCode), 10)[0])
|
|
}
|