package bhomeclient import ( "encoding/json" "errors" ) 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""` } type FileArg struct { 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"` } func (r *Request) Header(key string) string { if values, ok := r.HeaderMap[key]; ok { return values[0] } return "" } func (r *Request) Query(key string) string { if values, ok := r.QueryMap[key]; ok { return values[0] } return "" } func (r *Request) PostForm(key string) string { if values, ok := r.PostFormMap[key]; ok { return values[0] } return "" } func (r *Request) BindJSON(v interface{}) error { 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 } return nil, errors.New("file not found") } func (r *Request) FormFiles() (*[]FileArg, error) { if r.MultiFiles != nil && len(r.MultiFiles) >0 { return &r.MultiFiles, nil } return nil,errors.New("multi files not found") }