http_options.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package requests
  2. type HttpOptions struct {
  3. Type string
  4. Value interface{}
  5. }
  6. // milliseconds
  7. func HttpWriteTimeout(timeout int64) HttpOptions {
  8. return HttpOptions{"write_timeout", timeout}
  9. }
  10. // milliseconds
  11. func HttpReadTimeout(timeout int64) HttpOptions {
  12. return HttpOptions{"read_timeout", timeout}
  13. }
  14. func HttpHeader(header map[string]string) HttpOptions {
  15. return HttpOptions{"header", header}
  16. }
  17. // which is used for params with in url
  18. func HttpParams(params map[string]string) HttpOptions {
  19. return HttpOptions{"params", params}
  20. }
  21. // which is used for POST method only
  22. func HttpPayload(payload map[string]string) HttpOptions {
  23. return HttpOptions{"payload", payload}
  24. }
  25. // which is used for POST method only
  26. func HttpPayloadText(payload string) HttpOptions {
  27. return HttpOptions{"payloadText", payload}
  28. }
  29. // which is used for POST method only
  30. func HttpPayloadJson(payload interface{}) HttpOptions {
  31. return HttpOptions{"payloadJson", payload}
  32. }
  33. func HttpWithDirectReferer() HttpOptions {
  34. return HttpOptions{"directReferer", true}
  35. }
  36. func HttpWithRetCode(retCode *int) HttpOptions {
  37. return HttpOptions{"retCode", retCode}
  38. }