decodeJSONWithLimit is the size-configurable variant. Use this for endpoints that accept large payloads (e.g. bulk-import) where the default cap is too small — but always pass an explicit cap, never remove the wrapper.
(r *http.Request, v interface{}, maxBytes int64)
| 1936 | // default cap is too small — but always pass an explicit cap, never |
| 1937 | // remove the wrapper. |
| 1938 | func decodeJSONWithLimit(r *http.Request, v interface{}, maxBytes int64) error { |
| 1939 | // http.MaxBytesReader.Close() is a no-op; the decoder leaves r.Body at |
| 1940 | // EOF anyway. Setting this here also lets the server return a 413 |
| 1941 | // automatically via the error we wrap below. |
| 1942 | if r.Body != nil { |
| 1943 | r.Body = http.MaxBytesReader(nil, r.Body, maxBytes) |
| 1944 | } |
| 1945 | if err := json.NewDecoder(r.Body).Decode(v); err != nil { |
| 1946 | return fmt.Errorf("invalid JSON: %w", err) |
| 1947 | } |
| 1948 | return nil |
| 1949 | } |
| 1950 | |
| 1951 | // getWorkspaceID resolves workspace slug/ID from the request. |
| 1952 | // If RequireWorkspaceAccess already resolved the workspace, reads from context. |