merge master && fix both modify

This commit is contained in:
2025-01-26 14:32:59 +08:00
16 changed files with 536 additions and 153 deletions

View File

@ -10,6 +10,7 @@ package request
import (
"bytes"
"errors"
"github.com/mcuadros/go-defaults"
"io"
"net/http"
"strings"
@ -48,21 +49,27 @@ func (f *form) Parse(ctx *gin.Context, receiver interface{}) error {
method == http.MethodTrace ||
method == http.MethodConnect ||
method == http.MethodOptions {
return ctx.ShouldBindQuery(receiver)
}
if method == http.MethodPost ||
if err := ctx.ShouldBindQuery(receiver); nil != err {
return err
}
} else if method == http.MethodPost ||
method == http.MethodPut ||
method == http.MethodDelete {
if ContentType.IsJson(ctx) {
return ctx.ShouldBindJSON(receiver)
if err := ctx.ShouldBindJSON(receiver); nil != err {
return err
}
} else if ContentType.IsFormURLEncoded(ctx) {
if err := ctx.ShouldBind(receiver); nil != err {
return err
}
} else {
return errors.New(ctx.ContentType() + " is not support")
}
if ContentType.IsFormURLEncoded(ctx) {
return ctx.ShouldBind(receiver)
}
return errors.New(ctx.ContentType() + " is not support")
} else {
return errors.New(method + " : request method is not support")
}
return errors.New(method + " : request method is not support")
// 设置默认值
defaults.SetDefaults(receiver)
return nil
}