feat: use go:embed to embed templates (#1756)
This commit is contained in:
26
tools/goctl/api/gogen/handler.tpl
Normal file
26
tools/goctl/api/gogen/handler.tpl
Normal file
@@ -0,0 +1,26 @@
|
||||
package {{.PkgName}}
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
{{if .After1_1_10}}"github.com/zeromicro/go-zero/rest/httpx"{{end}}
|
||||
{{.ImportPackages}}
|
||||
)
|
||||
|
||||
func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
{{if .HasRequest}}var req types.{{.RequestType}}
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
{{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx)
|
||||
{{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}})
|
||||
if err != nil {
|
||||
httpx.Error(w, err)
|
||||
} else {
|
||||
{{if .HasResp}}httpx.OkJson(w, resp){{else}}httpx.Ok(w){{end}}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user