func (this *contextImplement) parseInput() { //取出get数据 request := this.request queryInput := request.URL.RawQuery //取出post数据 postInput := "" ct := request.Header.Get("Content-Type") if ct == "" { ct = "application/octet-stream" } ct, _, err := mime.ParseMediaType(ct) if ct == "application/x-www-form-urlencoded" && this.request.Body != nil { byteArray, err := ioutil.ReadAll(this.request.Body) if err != nil { panic(err) } this.request.Body = ioutil.NopCloser(bytes.NewReader(byteArray)) postInput = string(byteArray) } //解析数据 input := queryInput + "&" + postInput this.inputData = map[string]interface{}{} err = encoding.DecodeUrlQuery([]byte(input), &this.inputData) if err != nil { language.Throw(1, err.Error()) } }
func (this *contextImplement) GetParamToStruct(requireStruct interface{}) { //导出到struct err := language.MapToArray(this.inputData, requireStruct, "url") if err != nil { language.Throw(1, err.Error()) } }
func (this *contextImplement) GetFormParamToStruct(requireStruct interface{}) { if this.GetMethod() != "POST" { language.Throw(1, "请求Method不是POST方法") } this.GetParamToStruct(requireStruct) }