Mercurial > gemma
diff pkg/middleware/json.go @ 4164:6f9d00c8cc38
Made 'golint' and 'staticcheck' happy with middleware package.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 02 Aug 2019 18:13:58 +0200 |
parents | ef59a4255670 |
children | 4394daeea96a |
line wrap: on
line diff
--- a/pkg/middleware/json.go Fri Aug 02 18:01:32 2019 +0200 +++ b/pkg/middleware/json.go Fri Aug 02 18:13:58 2019 +0200 @@ -24,12 +24,22 @@ const jsonInputKey jsonInputKeyType = 0 +// DefaultLimit limits the incoming JSON payload to 2K to +// prevent flooding the server. const DefaultLimit = 2048 +// GetJSONInput returns the deserialized JSON data from +// the incoming request if any. func GetJSONInput(req *http.Request) interface{} { return req.Context().Value(jsonInputKey) } +// JSONInput is a middleware to deserialize the incomming +// request body to a object to be created by a given input function +// and stores the result into the context. +// GetJSONInput can be used to receive the deserialized data. +// limit limits the size of the incoming body to prevent +// flooding the server. func JSONInput(next http.Handler, input func(*http.Request) interface{}, limit int64) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {