From 966138e4021dc507b1db22ee5a5e73bdb8fac603 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 12 Apr 2018 11:57:11 +0900 Subject: [PATCH] ing --- servlet/rest-servlet.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/servlet/rest-servlet.go b/servlet/rest-servlet.go index da2fa4b..85ff4e8 100644 --- a/servlet/rest-servlet.go +++ b/servlet/rest-servlet.go @@ -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) } }