| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package http
- import (
- "net/http"
- "os"
- )
- type HttpParameter struct {
- jsonParamer string
- params map[string]interface{}
- files map[string]*os.File
- listFiles map[string][]*os.File
- httpMethod string
- }
- func NewGetHttpParameter() *HttpParameter {
- param := HttpParameter{
- params: make(map[string]interface{}),
- files: make(map[string]*os.File),
- listFiles: make(map[string][]*os.File),
- httpMethod: http.MethodGet,
- }
- return ¶m
- }
- func NewPostHttpParameter() *HttpParameter {
- param := HttpParameter{
- params: make(map[string]interface{}),
- files: make(map[string]*os.File),
- listFiles: make(map[string][]*os.File),
- httpMethod: http.MethodPost,
- }
- return ¶m
- }
- func (h *HttpParameter) JsonParamer() string {
- return h.jsonParamer
- }
- func (h *HttpParameter) SetJsonParamer(jsonParamer string) {
- h.jsonParamer = jsonParamer
- }
- func (h *HttpParameter) Params() map[string]interface{} {
- return h.params
- }
- func (h *HttpParameter) AddParam(key string, value interface{}) {
- h.params[key] = value
- }
- func (h *HttpParameter) SetParams(params map[string]interface{}) {
- h.params = params
- }
- func (h *HttpParameter) Files() map[string]*os.File {
- return h.files
- }
- func (h *HttpParameter) AddFiles(key string, file *os.File) {
- h.files[key] = file
- }
- func (h *HttpParameter) SetFiles(files map[string]*os.File) {
- h.files = files
- }
- func (h *HttpParameter) ListFiles() map[string][]*os.File {
- return h.listFiles
- }
- func (h *HttpParameter) AddListFiles(key string, listFiles []*os.File) {
- h.listFiles[key] = listFiles
- }
- func (h *HttpParameter) SetListFiles(listFiles map[string][]*os.File) {
- h.listFiles = listFiles
- }
- func (h *HttpParameter) HttpMethod() string {
- return h.httpMethod
- }
- func (h *HttpParameter) IsJson() bool {
- if len(h.jsonParamer) == 0 {
- return false
- }
- return true
- }
- func (h *HttpParameter) IsMultipart() bool {
- if len(h.files) == 0 && len(h.listFiles) == 0 {
- return false
- }
- return true
- }
|