| | |
| | | package bhomeclient |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "errors" |
| | | jsoniter "github.com/json-iterator/go" |
| | | ) |
| | | |
| | | type Request struct { |
| | | Path string `json:"path"` |
| | | Method string `json:"method"` |
| | | ContentType string `json:"contentType"` |
| | | HeaderMap map[string][]string `json:"headerMap"` |
| | | QueryMap map[string][]string `json:"queryMap"` |
| | | FormMap map[string][]string `json:"formMap"` |
| | | PostFormMap map[string][]string `json:"postFormMap"` |
| | | Body []byte `json:"body"` |
| | | File FileArg `json:"file"` |
| | | MultiFiles []FileArg `json:"multiFiles""` |
| | | Path string `json:"path"` |
| | | Method string `json:"method"` |
| | | ContentType string `json:"contentType"` |
| | | HeaderMap map[string][]string `json:"headerMap"` |
| | | QueryMap map[string][]string `json:"queryMap"` |
| | | FormMap map[string][]string `json:"formMap"` |
| | | PostFormMap map[string][]string `json:"postFormMap"` |
| | | Body []byte `json:"body"` |
| | | File FileArg `json:"file"` |
| | | MultiFiles []FileArg `json:"multiFiles""` |
| | | |
| | | SrcProc ProcInfo `json:"srcProc"` //请求来源进程 |
| | | SrcProc ProcInfo `json:"srcProc"` //请求来源进程 |
| | | } |
| | | |
| | | type FileArg struct { |
| | | Name string `json:"name"` |
| | | Size int64 `json:"size"` |
| | | Bytes []byte `json:"bytes"` |
| | | Name string `json:"name"` |
| | | Size int64 `json:"size"` |
| | | Bytes []byte `json:"bytes"` |
| | | } |
| | | |
| | | type Reply struct { |
| | | Success bool `json:"success"` |
| | | Msg string `json:"msg"` |
| | | Data interface{} `json:"data"` |
| | | Success bool `json:"success"` |
| | | Msg string `json:"msg"` |
| | | Data interface{} `json:"data"` |
| | | } |
| | | |
| | | func (r *Request) Header(key string) string { |
| | |
| | | } |
| | | |
| | | func (r *Request) BindJSON(v interface{}) error { |
| | | var json = jsoniter.ConfigCompatibleWithStandardLibrary |
| | | return json.Unmarshal(r.Body, &v) |
| | | } |
| | | |
| | | func (r *Request) FormFile() (*FileArg, error) { |
| | | if r.File.Name != "" && r.File.Size >0 && r.File.Bytes !=nil { |
| | | return &r.File,nil |
| | | if r.File.Name != "" && r.File.Size > 0 && r.File.Bytes != nil { |
| | | return &r.File, nil |
| | | } |
| | | return nil, errors.New("file not found") |
| | | } |
| | | |
| | | func (r *Request) FormFiles() (*[]FileArg, error) { |
| | | if r.MultiFiles != nil && len(r.MultiFiles) >0 { |
| | | if r.MultiFiles != nil && len(r.MultiFiles) > 0 { |
| | | return &r.MultiFiles, nil |
| | | } |
| | | return nil,errors.New("multi files not found") |
| | | return nil, errors.New("multi files not found") |
| | | } |