http_options.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package http_requests
  2. import "io"
  3. type HttpOptions struct {
  4. Type string
  5. Value interface{}
  6. }
  7. // milliseconds
  8. func HttpWriteTimeout(timeout int64) HttpOptions {
  9. return HttpOptions{"write_timeout", timeout}
  10. }
  11. // milliseconds
  12. func HttpReadTimeout(timeout int64) HttpOptions {
  13. return HttpOptions{"read_timeout", timeout}
  14. }
  15. func HttpHeader(header map[string]string) HttpOptions {
  16. return HttpOptions{"header", header}
  17. }
  18. // which is used for params with in url
  19. func HttpParams(params map[string]string) HttpOptions {
  20. return HttpOptions{"params", params}
  21. }
  22. // which is used for POST method only
  23. func HttpPayload(payload map[string]string) HttpOptions {
  24. return HttpOptions{"payload", payload}
  25. }
  26. // which is used for POST method only
  27. func HttpPayloadText(payload string) HttpOptions {
  28. return HttpOptions{"payloadText", payload}
  29. }
  30. // which is used for POST method only
  31. func HttpPayloadJson(payload interface{}) HttpOptions {
  32. return HttpOptions{"payloadJson", payload}
  33. }
  34. // which is used for POST method only
  35. // payload follows the form data format, and files is a map from filename to file
  36. func HttpPayloadMultipart(payload map[string]string, files map[string]io.Reader) HttpOptions {
  37. return HttpOptions{"payloadMultipart", map[string]interface{}{
  38. "payload": payload,
  39. "files": files,
  40. }}
  41. }
  42. func HttpRaiseErrorWhenStreamDataNotMatch(raise bool) HttpOptions {
  43. return HttpOptions{"raiseErrorWhenStreamDataNotMatch", raise}
  44. }
  45. func HttpWithDirectReferer() HttpOptions {
  46. return HttpOptions{"directReferer", true}
  47. }
  48. func HttpWithRetCode(retCode *int) HttpOptions {
  49. return HttpOptions{"retCode", retCode}
  50. }