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