zk_http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package client
  2. import (
  3. "git.finogeeks.club/base/apm"
  4. "github.com/gin-gonic/gin"
  5. "github.com/go-resty/resty/v2"
  6. )
  7. /*c,需要在业务层传递*/
  8. func SendByGoRetry(c *gin.Context, url, method string, headers map[string]string, body []byte) (*resty.Response, error) {
  9. traceCtx := apm.ApmClient().TraceContextFromGin(c)
  10. traceSpanId, exists := c.Get("zipkin_span_id")
  11. if exists {
  12. value, exists := c.Get("zipkin_trace_span_id_" + traceSpanId.(string))
  13. if exists && value != nil {
  14. headers["Zipkin-Span-Context"] = value.(string)
  15. }
  16. }
  17. var rsp *resty.Response
  18. var err error
  19. switch method {
  20. case "GET":
  21. rsp, err = Request(traceCtx).SetHeaders(headers).SetBody(body).Get(url)
  22. break
  23. case "POST":
  24. rsp, err = Request(traceCtx).SetHeaders(headers).SetBody(body).Post(url)
  25. break
  26. case "PUT":
  27. rsp, err = Request(traceCtx).SetHeaders(headers).SetBody(body).Put(url)
  28. break
  29. case "DELETE":
  30. rsp, err = Request(traceCtx).SetHeaders(headers).SetBody(body).Delete(url)
  31. break
  32. case "PATCH":
  33. rsp, err = Request(traceCtx).SetHeaders(headers).SetBody(body).Patch(url)
  34. break
  35. }
  36. return rsp, err
  37. }