The documentation updates and bug fixes for the framework are progressing too slowly.
Has the author considered adopting other methods to promote community development? Currently, maintaining an old project built with go-zero is particularly challenging, as there are many hidden logic pieces that cannot be found in the documentation and can only be identified by digging into the source code. For example:
- In the httpx package, the maximum parseable body size is limited to 8MB, hardcoded in the code and cannot be modified (there is an issue #2633 for this, but it was closed due to lack of attention).
- In the httpx package, ErrorCtx defaults to returning a 400 status code, and errors are directly printed out, rather than being formatted as JSON.
Besides these issues, there are many other aspects that feel inconvenient during development.
i couldn't agree more body size is limited to 8MB is unacceptable
Thank you for your feedback, we are actively working on improving and updating the documentation, and your feedback is very helpful to us in updating the documentation.
Workaround: Bypassing httpx.Parse 8MB Limit
I encountered the same issue where httpx.Parse has a hardcoded 8MB request body size limit. While this is just a temporary workaround, I'm sharing it to help others until the community provides a proper solution.
Note: This is a workaround, not an ideal solution. I hope the maintainers can address this limitation in future releases by making the size limit configurable.
Temporary Workaround
// 自定义解析函数,支持大于8MB的数据
func parseRequest(r *http.Request, req interface{}) error {
contentType := r.Header.Get("Content-Type")
// 检查Content-Type
if !strings.Contains(contentType, "application/json") {
return fmt.Errorf("unsupported content type: %s", contentType)
}
// 设置最大读取大小,比如50MB
const maxBodySize = 50 << 20 // 50MB
limitedReader := io.LimitReader(r.Body, maxBodySize)
// 读取请求体
body, err := io.ReadAll(limitedReader)
if err != nil {
return fmt.Errorf("failed to read request body: %w", err)
}
// 检查是否达到大小限制
if int64(len(body)) == maxBodySize {
return fmt.Errorf("request body too large, exceeds %d bytes", maxBodySize)
}
// JSON解析
if err := json.Unmarshal(body, req); err != nil {
return fmt.Errorf("failed to unmarshal JSON: %w", err)
}
return nil
}
Usage
// Replace httpx.Parse(r, &requestData)
var requestData YourRequestStruct
if err := parseRequest(r, &requestData); err != nil {
// Handle error
http.Error(w, err.Error(), http.StatusBadRequest)
return
}