REST 接口接收内容为空时,默认为 {}

This commit is contained in:
GoEdgeLab
2022-09-24 18:35:29 +08:00
parent 07eb5531e4
commit 7db5a8174e

View File

@@ -170,6 +170,11 @@ func (this *RestServer) handle(writer http.ResponseWriter, req *http.Request) {
return
}
// 如果为空,表示传的数据为空
if len(body) == 0 {
body = []byte("{}")
}
// 请求数据
var reqValue = reflect.New(method.Type().In(1).Elem()).Interface()
err = json.Unmarshal(body, reqValue)