|
@@ -23,14 +23,14 @@ import (
|
|
|
|
|
|
func {{.HandlerName}}(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
- var req types.{{.RequestType}}
|
|
|
+ {{if .HasRequest}}var req types.{{.RequestType}}
|
|
|
if err := httpx.Parse(r, &req); err != nil {
|
|
|
httpx.Error(w, err)
|
|
|
return
|
|
|
- }
|
|
|
+ }{{end}}
|
|
|
|
|
|
l := logic.New{{.LogicType}}(r.Context(), ctx)
|
|
|
- {{if .HasResp}}resp, {{end}}err := l.{{.Call}}(req)
|
|
|
+ {{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}req{{end}})
|
|
|
if err != nil {
|
|
|
httpx.Error(w, err)
|
|
|
} else {
|
|
@@ -47,6 +47,7 @@ type Handler struct {
|
|
|
LogicType string
|
|
|
Call string
|
|
|
HasResp bool
|
|
|
+ HasRequest bool
|
|
|
}
|
|
|
|
|
|
func genHandler(dir string, group spec.Group, route spec.Route) error {
|
|
@@ -71,6 +72,7 @@ func genHandler(dir string, group spec.Group, route spec.Route) error {
|
|
|
LogicType: strings.TrimSuffix(strings.Title(handler), "Handler") + "Logic",
|
|
|
Call: strings.Title(strings.TrimSuffix(handler, "Handler")),
|
|
|
HasResp: len(route.ResponseType.Name) > 0,
|
|
|
+ HasRequest: len(route.RequestType.Name) > 0,
|
|
|
})
|
|
|
}
|
|
|
|