Skip to content

Commit

Permalink
feat: support multipart/form-data format request (songquanpeng#1690)
Browse files Browse the repository at this point in the history
* "add parser multipart/form-data"

* chore: fix impl

* chore: update impl

---------

Co-authored-by: JustSong <[email protected]>
  • Loading branch information
2 people authored and mxdlzg committed Oct 15, 2024
1 parent e04626f commit 489334d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions common/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error {
contentType := c.Request.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "application/json") {
err = json.Unmarshal(requestBody, &v)
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
} else {
// skip for now
// TODO: someday non json request have variant model, we will need to implementation this
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
err = c.ShouldBind(&v)
}
if err != nil {
return err
}
// Reset request body
c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion middleware/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type ModelRequest struct {
Model string `json:"model"`
Model string `json:"model" form:"model"`
}

func Distribute() func(c *gin.Context) {
Expand Down

0 comments on commit 489334d

Please sign in to comment.