HttpParameter.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package http
  2. import (
  3. "net/http"
  4. "os"
  5. )
  6. type HttpParameter struct {
  7. jsonParamer string
  8. params map[string]interface{}
  9. files map[string]*os.File
  10. listFiles map[string][]*os.File
  11. httpMethod string
  12. }
  13. func NewGetHttpParameter() *HttpParameter {
  14. param := HttpParameter{
  15. params: make(map[string]interface{}),
  16. files: make(map[string]*os.File),
  17. listFiles: make(map[string][]*os.File),
  18. httpMethod: http.MethodGet,
  19. }
  20. return &param
  21. }
  22. func NewPostHttpParameter() *HttpParameter {
  23. param := HttpParameter{
  24. params: make(map[string]interface{}),
  25. files: make(map[string]*os.File),
  26. listFiles: make(map[string][]*os.File),
  27. httpMethod: http.MethodPost,
  28. }
  29. return &param
  30. }
  31. func (h *HttpParameter) JsonParamer() string {
  32. return h.jsonParamer
  33. }
  34. func (h *HttpParameter) SetJsonParamer(jsonParamer string) {
  35. h.jsonParamer = jsonParamer
  36. }
  37. func (h *HttpParameter) Params() map[string]interface{} {
  38. return h.params
  39. }
  40. func (h *HttpParameter) AddParam(key string, value interface{}) {
  41. h.params[key] = value
  42. }
  43. func (h *HttpParameter) SetParams(params map[string]interface{}) {
  44. h.params = params
  45. }
  46. func (h *HttpParameter) Files() map[string]*os.File {
  47. return h.files
  48. }
  49. func (h *HttpParameter) AddFiles(key string, file *os.File) {
  50. h.files[key] = file
  51. }
  52. func (h *HttpParameter) SetFiles(files map[string]*os.File) {
  53. h.files = files
  54. }
  55. func (h *HttpParameter) ListFiles() map[string][]*os.File {
  56. return h.listFiles
  57. }
  58. func (h *HttpParameter) AddListFiles(key string, listFiles []*os.File) {
  59. h.listFiles[key] = listFiles
  60. }
  61. func (h *HttpParameter) SetListFiles(listFiles map[string][]*os.File) {
  62. h.listFiles = listFiles
  63. }
  64. func (h *HttpParameter) HttpMethod() string {
  65. return h.httpMethod
  66. }
  67. func (h *HttpParameter) IsJson() bool {
  68. if len(h.jsonParamer) == 0 {
  69. return false
  70. }
  71. return true
  72. }
  73. func (h *HttpParameter) IsMultipart() bool {
  74. if len(h.files) == 0 && len(h.listFiles) == 0 {
  75. return false
  76. }
  77. return true
  78. }