request.go 398 B

123456789101112131415161718192021222324252627282930
  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 Requests() HandlerFunc {
  15. return func(ctx *Context) {
  16. if action := ctx.Action(); action != nil {
  17. if s, ok := action.(Requester); ok {
  18. s.SetRequest(ctx.Req())
  19. }
  20. }
  21. ctx.Next()
  22. }
  23. }