Skip to content

Commit

Permalink
Merge pull request #48 from chenjink674/20240723.addMultipart
Browse files Browse the repository at this point in the history
20240723.add multipart
  • Loading branch information
zhufuyi authored Jul 23, 2024
2 parents 948abcf + d6ec6e3 commit 42a01bf
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/protoc-gen-go-gin/internal/generate/router/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,18 @@ type {{$.LowerName}}Router struct {
wrapCtxFn func(c *gin.Context) context.Context
}
func (r *{{$.LowerName}}Router) register() {
{{range .Methods}}{{if eq .InvokeType 0}}{{if .Path}}r.iRouter.Handle("{{.Method}}", "{{.Path}}", r.withMiddleware("{{.Method}}", "{{.Path}}", r.{{ .HandlerName }})...){{end}}{{end}}
{{range .Methods}}
{{if eq .InvokeType 0}}
{{if .Path}}
{{if eq .Method "FORM-DATA" }}
r.iRouter.Handle("POST", "{{.Path}}", r.withMiddleware("POST", "{{.Path}}", r.{{ .HandlerName }})...)
{{else}}
r.iRouter.Handle("{{.Method}}", "{{.Path}}", r.withMiddleware("{{.Method}}", "{{.Path}}", r.{{ .HandlerName }})...)
{{end}}
{{end}}
{{end}}
{{end}}
}
Expand Down Expand Up @@ -164,6 +174,15 @@ var _ middleware.CtxKeyString
return
}
{{end}}
{{if eq .Method "FORM-DATA" }}
if err = c.ShouldBindWith(req, binding.FormMultipart); err != nil {
r.zapLog.Warn("ShouldBindWith error", zap.Error(err), middleware.GCtxRequestIDField(c))
r.iResponse.ParamError(c, err)
return
}
{{end}}
{{if eq .Method "GET" "DELETE" }}
if err = c.ShouldBindQuery(req); err != nil {
r.zapLog.Warn("ShouldBindQuery error", zap.Error(err), middleware.GCtxRequestIDField(c))
Expand Down

0 comments on commit 42a01bf

Please sign in to comment.