http_options.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. type HttpPayloadMultipartFile struct {
  35. Filename string
  36. Reader io.Reader
  37. }
  38. // which is used for POST method only
  39. // payload follows the form data format, and files is a map from filename to file
  40. func HttpPayloadMultipart(payload map[string]string, files map[string]HttpPayloadMultipartFile) HttpOptions {
  41. return HttpOptions{"payloadMultipart", map[string]interface{}{
  42. "payload": payload,
  43. "files": files,
  44. }}
  45. }
  46. func HttpRaiseErrorWhenStreamDataNotMatch(raise bool) HttpOptions {
  47. return HttpOptions{"raiseErrorWhenStreamDataNotMatch", raise}
  48. }
  49. func HttpWithDirectReferer() HttpOptions {
  50. return HttpOptions{"directReferer", true}
  51. }
  52. func HttpWithRetCode(retCode *int) HttpOptions {
  53. return HttpOptions{"retCode", retCode}
  54. }