This commit is contained in:
crusader 2018-04-12 11:57:11 +09:00
parent cb16130245
commit 966138e402

View File

@ -1,6 +1,7 @@
package servlet package servlet
import ( import (
"encoding/json"
"fmt" "fmt"
"reflect" "reflect"
@ -97,17 +98,22 @@ func (s *RESTServlets) HandleGet(servletCtx server.ServletCtx, ctx *fasthttp.Req
func (s *RESTServlets) HandlePost(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, mapping *MethodMapping) *csw.Error { func (s *RESTServlets) HandlePost(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, mapping *MethodMapping) *csw.Error {
params := make([]string, 0) params := make([]string, 0)
if nil != mapping.ParamKeys { if nil != mapping.ParamKeys {
pargs := ctx.PostArgs() buf := ctx.PostBody()
if nil == pargs { if nil == buf || 0 == len(buf) {
return csw.NewError(fasthttp.StatusBadRequest, fmt.Errorf("Parameter is not valied")) return csw.NewError(fasthttp.StatusBadRequest, fmt.Errorf("Parameter is not valied"))
} }
var jsonMap map[string]string
if err := json.Unmarshal(buf, jsonMap); nil != err {
return csw.NewError(fasthttp.StatusBadRequest, fmt.Errorf("Parameter is not valied %v", err))
}
for _, k := range mapping.ParamKeys { for _, k := range mapping.ParamKeys {
buf := pargs.Peek(k) v, ok := jsonMap[k]
if nil == buf { if !ok {
return csw.NewError(fasthttp.StatusBadRequest, fmt.Errorf("Parameter for %s is not valied", k)) return csw.NewError(fasthttp.StatusBadRequest, fmt.Errorf("Parameter for %s is not valied", k))
} }
params = append(params, string(buf)) params = append(params, v)
} }
} }