3
0

Do not decode JSON from body if no POST params are spec.

This commit is contained in:
Denis Arh
2021-03-08 17:42:16 +01:00
parent 186b6cb99e
commit 82c76bbe6c
37 changed files with 214 additions and 1261 deletions

View File

@@ -28,6 +28,10 @@ var (
_ = chi.URLParam
_ = multipart.ErrMessageTooLarge
_ = payload.ParseUint64s
_ = strings.ToLower
_ = io.EOF
_ = fmt.Errorf
_ = json.NewEncoder
)
type (
@@ -72,6 +76,7 @@ func (r {{ export $.Endpoint.Entrypoint $a.Name }}) Get{{ export $p.Name }}() {{
// Fill processes request and fills internal variables
func (r *{{ export $.Endpoint.Entrypoint $a.Name }}) Fill(req *http.Request) (err error) {
{{ if $a.Params.Post }}
if strings.ToLower(req.Header.Get("content-type")) == "application/json" {
err = json.NewDecoder(req.Body).Decode(r)
@@ -82,6 +87,7 @@ func (r *{{ export $.Endpoint.Entrypoint $a.Name }}) Fill(req *http.Request) (er
return fmt.Errorf("error parsing http request body: %w", err)
}
}
{{- end }}
{{ if $a.Params.Get }}