utils.go 661 B

12345678910111213141516171819202122232425262728293031323334
  1. package rest
  2. import (
  3. "context"
  4. httppkg "git.nspix.com/golang/micro/gateway/http"
  5. "net/http"
  6. )
  7. func HttpRequestFromContext(ctx context.Context) *http.Request {
  8. if v := ctx.Value(restCtxRequest); v != nil {
  9. if r, ok := v.(*http.Request); ok {
  10. return r
  11. }
  12. }
  13. return nil
  14. }
  15. func HttpResponseFromContext(ctx context.Context) *http.Response {
  16. if v := ctx.Value(restCtxResponse); v != nil {
  17. if r, ok := v.(*http.Response); ok {
  18. return r
  19. }
  20. }
  21. return nil
  22. }
  23. func HttpContextFromContext(ctx context.Context) *httppkg.Context {
  24. if v := ctx.Value(restCtxHttpctx); v != nil {
  25. if r, ok := v.(*httppkg.Context); ok {
  26. return r
  27. }
  28. }
  29. return nil
  30. }