chore: fix impl
This commit is contained in:
parent
16e9a14a7d
commit
a159fa9832
@ -24,30 +24,16 @@ func GetRequestBody(c *gin.Context) ([]byte, error) {
|
|||||||
return requestBody.([]byte), nil
|
return requestBody.([]byte), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModelRequest struct {
|
|
||||||
Model string `json:"model" form:"model"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func UnmarshalBodyReusable(c *gin.Context, v any) error {
|
func UnmarshalBodyReusable(c *gin.Context, v any) error {
|
||||||
var requestBody []byte
|
requestBody, err := GetRequestBody(c)
|
||||||
var err error
|
|
||||||
contentType := c.Request.Header.Get("Content-Type")
|
|
||||||
if strings.HasPrefix(contentType, "application/json") {
|
|
||||||
requestBody, err = GetRequestBody(c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(requestBody, &v)
|
contentType := c.Request.Header.Get("Content-Type")
|
||||||
}
|
if strings.HasPrefix(contentType, "application/json") {
|
||||||
if strings.HasPrefix(contentType, "multipart/form-data") {
|
|
||||||
var model ModelRequest
|
|
||||||
err = c.Bind(&model)
|
|
||||||
requestBody, err = json.Marshal(model)
|
|
||||||
err = json.Unmarshal(requestBody, &v)
|
err = json.Unmarshal(requestBody, &v)
|
||||||
} else {
|
} else {
|
||||||
|
err = c.ShouldBind(&v)
|
||||||
// skip for now
|
|
||||||
// TODO: someday non json request have variant model, we will need to implementation this
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user