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)
| 1837 | // default cap is too small — but always pass an explicit cap, never |
| 1838 | // remove the wrapper. |
| 1839 | func decodeJSONWithLimit(r *http.Request, v interface{}, maxBytes int64) error { |
| 1840 | // http.MaxBytesReader.Close() is a no-op; the decoder leaves r.Body at |
| 1841 | // EOF anyway. Setting this here also lets the server return a 413 |
| 1842 | // automatically via the error we wrap below. |
| 1843 | if r.Body != nil { |
| 1844 | r.Body = http.MaxBytesReader(nil, r.Body, maxBytes) |
| 1845 | } |
| 1846 | if err := json.NewDecoder(r.Body).Decode(v); err != nil { |
| 1847 | return fmt.Errorf("invalid JSON: %w", err) |
| 1848 | } |
| 1849 | return nil |
| 1850 | } |
| 1851 | |
| 1852 | // getWorkspaceID resolves workspace slug/ID from the request. |
| 1853 | // If RequireWorkspaceAccess already resolved the workspace, reads from context. |