Skip to content

Commit

Permalink
add hertz engine support for option for generate interface method cod…
Browse files Browse the repository at this point in the history
…e that contain HTTP Request Context
  • Loading branch information
alimy committed Feb 10, 2024
1 parent b777fba commit 5eccc7b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/generator/templates/hertz_iface.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type {{.TypeName}} interface {
{{if notEmptyStr .Chain }}// Chain provide handlers chain for hertz
{{.Chain}}() []app.HandlerFunc
{{end}}
{{range .Fields}} {{if .JustUseContext }}{{ .MethodName}}(context.Context, *app.RequestContext){{else}}{{.MethodName}}({{if .IsUseContext }}context.Context, *app.RequestContext{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName }}*{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}}
{{range .Fields}} {{if .JustUseContext }}{{ .MethodName}}(context.Context, *app.RequestContext){{else}}{{.MethodName}}({{if .IsUseRequestContext }}context.Context{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}context.Context, *app.RequestContext{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName }}*{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}}
{{end}}

mustEmbedUnimplemented{{.TypeName}}Servant()
Expand Down Expand Up @@ -88,7 +88,7 @@ func Register{{.TypeName}}Servant(e *route.Engine, s {{.TypeName}}{{if .IsUseFie
}
{{- end }}
{{if notEmptyStr .OutName -}}
resp, err := s.{{ .MethodName}}({{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})
resp, err := s.{{ .MethodName}}({{if .IsUseRequestContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})
{{if .IsRenderOut -}}
if err != nil {
s.Render(c, ctx, nil, err)
Expand All @@ -100,7 +100,7 @@ func Register{{.TypeName}}Servant(e *route.Engine, s {{.TypeName}}{{if .IsUseFie
s.Render(c, ctx, resp, err)
{{- end }}
{{- else -}}
s.Render(c, ctx, nil, s.{{.MethodName}}({{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}))
s.Render(c, ctx, nil, s.{{.MethodName}}({{if .IsUseRequestContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}))
{{- end }}
}{{end}}{{if .IsFieldChain }})...{{end}})
{{else if .JustHttpAny}} router.Any("{{.Path}}", {{if .IsFieldChain }}append(cc.Chain{{.MethodName}}(), {{end}}{{if .JustUseContext}}s.{{ .MethodName}}{{else}}func(c context.Context, ctx *app.RequestContext) {
Expand All @@ -124,7 +124,7 @@ func Register{{.TypeName}}Servant(e *route.Engine, s {{.TypeName}}{{if .IsUseFie
}
{{- end }}
{{if notEmptyStr .OutName -}}
resp, err := s.{{ .MethodName}}({{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})
resp, err := s.{{ .MethodName}}({{if .IsUseRequestContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})
{{if .IsRenderOut -}}
if err != nil {
s.Render(c, ctx, nil, err)
Expand All @@ -136,7 +136,7 @@ func Register{{.TypeName}}Servant(e *route.Engine, s {{.TypeName}}{{if .IsUseFie
s.Render(c, ctx, resp, err)
{{- end }}
{{- else -}}
s.Render(c, ctx, nil, s.{{.MethodName}}({{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}))
s.Render(c, ctx, nil, s.{{.MethodName}}({{if .IsUseRequestContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}))
{{- end }}
}{{end}}{{if .IsFieldChain }})...{{end}})
{{else}}{{$field := .}} {
Expand All @@ -161,7 +161,7 @@ func Register{{.TypeName}}Servant(e *route.Engine, s {{.TypeName}}{{if .IsUseFie
}
{{- end }}
{{if notEmptyStr .OutName -}}
resp, err := s.{{ .MethodName}}({{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})
resp, err := s.{{ .MethodName}}({{if .IsUseRequestContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}})
{{if .IsRenderOut -}}
if err != nil {
s.Render(c, ctx, nil, err)
Expand All @@ -173,7 +173,7 @@ func Register{{.TypeName}}Servant(e *route.Engine, s {{.TypeName}}{{if .IsUseFie
s.Render(c, ctx, resp, err)
{{- end }}
{{- else -}}
s.Render(c, ctx, nil, s.{{.MethodName}}({{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}))
s.Render(c, ctx, nil, s.{{.MethodName}}({{if .IsUseRequestContext }}c{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}c, ctx{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName}}req{{end}}))
{{- end }}
}{{end}}{{if .IsFieldChain }}){{end}}
{{range .AnyHttpMethods}} router.Handle("{{.}}", "{{$field.Path}}", h{{if $field.IsFieldChain }}...{{end}})
Expand All @@ -193,7 +193,7 @@ func ({{$unimplementedServant}}){{.Chain}}() []app.HandlerFunc {

{{end}}
{{range .Fields}}
func ({{$unimplementedServant}}){{if .JustUseContext}}{{ .MethodName}}(c context.Context, ctx *app.RequestContext){{else}}{{.MethodName}}({{if .IsUseContext }}c context.Context, ctx *app.RequestContext{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName }}req *{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}} {
func ({{$unimplementedServant}}){{if .JustUseContext}}{{ .MethodName}}(c context.Context, ctx *app.RequestContext){{else}}{{.MethodName}}({{if .IsUseRequestContext }}c context.Context{{if notEmptyStr .InName }}, {{end}}{{end}}{{if .IsUseContext }}c context.Context, ctx *app.RequestContext{{if notEmptyStr .InName }}, {{end}}{{end}}{{if notEmptyStr .InName }}req *{{ .InName }}{{end}}) {{if notEmptyStr .OutName }}(*{{ .OutName}}, mir.Error){{else}}mir.Error{{end}}{{end}} {
{{if .JustUseContext -}}
ctx.String(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
{{else -}}
Expand Down

0 comments on commit 5eccc7b

Please sign in to comment.