request.go 366 B

12345678910111213141516171819202122232425262728
  1. package tango
  2. import (
  3. "net/http"
  4. )
  5. type Requester interface {
  6. SetRequest(*http.Request)
  7. }
  8. type Req struct {
  9. *http.Request
  10. }
  11. func (r *Req) SetRequest(req *http.Request) {
  12. r.Request = req
  13. }
  14. func RequestHandler(ctx *Context) {
  15. if action := ctx.Action(); action != nil {
  16. if s, ok := action.(Requester); ok {
  17. s.SetRequest(ctx.Req())
  18. }
  19. }
  20. ctx.Next()
  21. }