ing
This commit is contained in:
parent
cb16130245
commit
966138e402
|
@ -1,6 +1,7 @@
|
|||
package servlet
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"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 {
|
||||
params := make([]string, 0)
|
||||
if nil != mapping.ParamKeys {
|
||||
pargs := ctx.PostArgs()
|
||||
if nil == pargs {
|
||||
buf := ctx.PostBody()
|
||||
if nil == buf || 0 == len(buf) {
|
||||
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 {
|
||||
buf := pargs.Peek(k)
|
||||
if nil == buf {
|
||||
v, ok := jsonMap[k]
|
||||
if !ok {
|
||||
return csw.NewError(fasthttp.StatusBadRequest, fmt.Errorf("Parameter for %s is not valied", k))
|
||||
}
|
||||
params = append(params, string(buf))
|
||||
params = append(params, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user