writer.go 486 B

1234567891011121314151617181920212223242526272829303132
  1. package logger
  2. import (
  3. "net/http"
  4. "time"
  5. )
  6. type writer struct {
  7. w http.ResponseWriter
  8. s time.Time
  9. status int
  10. size int
  11. }
  12. func (this *writer) Header() http.Header {
  13. return this.w.Header()
  14. }
  15. func (this *writer) Write(bytes []byte) (int, error) {
  16. if this.status == 0 {
  17. this.status = http.StatusOK
  18. }
  19. size, err := this.w.Write(bytes)
  20. this.size += size
  21. return size, err
  22. }
  23. func (this *writer) WriteHeader(status int) {
  24. this.status = status
  25. this.w.WriteHeader(status)
  26. }