response_writer.go 708 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package gin
  2. import (
  3. "net/http"
  4. )
  5. type (
  6. ResponseWriter interface {
  7. http.ResponseWriter
  8. Status() int
  9. Written() bool
  10. // private
  11. reset(http.ResponseWriter)
  12. setStatus(int)
  13. }
  14. responseWriter struct {
  15. http.ResponseWriter
  16. status int
  17. written bool
  18. }
  19. )
  20. func (w *responseWriter) reset(writer http.ResponseWriter) {
  21. w.ResponseWriter = writer
  22. w.status = 0
  23. w.written = false
  24. }
  25. func (w *responseWriter) setStatus(code int) {
  26. w.status = code
  27. }
  28. func (w *responseWriter) WriteHeader(code int) {
  29. w.status = code
  30. w.written = true
  31. w.ResponseWriter.WriteHeader(code)
  32. }
  33. func (w *responseWriter) Status() int {
  34. return w.status
  35. }
  36. func (w *responseWriter) Written() bool {
  37. return w.written
  38. }