fwhHttpClient.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package fwh_pro
  2. import (
  3. "fwh-toolbox-server/utils/httpClient"
  4. "net/http"
  5. "net/url"
  6. "time"
  7. )
  8. const (
  9. timeout time.Duration = 60 // fwh请求超时60s
  10. )
  11. // FwhHttpInit
  12. func FwhHttpInit() {
  13. httpClient.RegisterLogin(reLogin)
  14. }
  15. // 仅用户登录或者不需要token的请求
  16. func FwhHttpGetWithoutToken(url string, params url.Values) (*httpClient.Response, error) {
  17. t := timeout
  18. opt := httpClient.HttpClientOptions{
  19. Timeout: &t,
  20. Header: &http.Header{
  21. "Accept": {"application/json", "text/plain", "*/*"},
  22. },
  23. }
  24. return httpClient.HttpGet(url, params, &opt)
  25. }
  26. func FwhHttpGet(url string, params url.Values) (*httpClient.Response, error) {
  27. t := timeout
  28. opt := httpClient.HttpClientOptions{
  29. Timeout: &t,
  30. Header: &http.Header{
  31. "Logintoken": {getLoginToken()},
  32. "Accept": {"application/json", "text/plain", "*/*"},
  33. },
  34. }
  35. return httpClient.HttpGet(url, params, &opt)
  36. }
  37. // 仅用户登录或者不需要token的请求
  38. func FwhHttpPostWithoutToken(url string, body any) (*httpClient.Response, error) {
  39. t := timeout
  40. opt := httpClient.HttpClientOptions{
  41. Timeout: &t,
  42. Header: &http.Header{
  43. "Accept": {"application/json", "text/plain", "*/*"},
  44. },
  45. }
  46. return httpClient.HttpPost(url, body, &opt)
  47. }
  48. func FwhHttpPost(url string, body any) (*httpClient.Response, error) {
  49. t := timeout
  50. opt := httpClient.HttpClientOptions{
  51. Timeout: &t,
  52. Header: &http.Header{
  53. "Logintoken": {getLoginToken()},
  54. "Accept": {"application/json", "text/plain", "*/*"},
  55. },
  56. }
  57. return httpClient.HttpPost(url, body, &opt)
  58. }