Skip to content

Commit

Permalink
fix panic in multipart data
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannm committed Apr 9, 2024
1 parent 5ceab09 commit 7b80f2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions example/ex-02-rest/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ var SampleDesc desc.ServiceDescFunc = func() *desc.Service {
Selector(fasthttp.REST(http.MethodPost, "/raw_echo")).
Selector(fasthttp.RPC("rawEcho")).
SetHandler(RawEchoHandler),
).
AddContract(
desc.NewContract().
SetInput(kit.MultipartFormMessage{}).
SetOutput(kit.RawMessage{}).
Selector(fasthttp.REST(http.MethodPost, "/upload")).
SetHandler(UploadHandler),
)
}

Expand Down Expand Up @@ -132,3 +139,16 @@ func Redirect(ctx *kit.Context) {
rc := ctx.Conn().(kit.RESTConn) //nolint:forcetypeassert
rc.Redirect(http.StatusTemporaryRedirect, req.URL)
}

func UploadHandler(ctx *kit.Context) {
//nolint:forcetypeassert
req := ctx.In().GetMsg().(kit.MultipartFormMessage)

frm := req.GetForm()
fmt.Println(frm.File)

ctx.In().Reply().
SetHdr("Content-Type", "application/json").
SetMsg(kit.RawMessage{}).
Send()
}
4 changes: 4 additions & 0 deletions kit/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func CreateMessageFactory(in Message) MessageFactoryFunc {
return func() Message {
return RawMessage{}
}
case reflect.Indirect(reflect.ValueOf(in)).Type() == reflect.TypeOf(MultipartFormMessage{}):
return func() Message {
return MultipartFormMessage{}
}
}

var ff MessageFactoryFunc
Expand Down

0 comments on commit 7b80f2f

Please sign in to comment.