go-zero
go-zero copied to clipboard
When i DIY handle.tpl, it's not work well.
I have according this document: https://go-zero.dev/cn/docs/advance/template to DIY my api output,but it's fully copy handle.tpl to internal/handler/xxxhandler.go
I think document maybe have some mistakes. when i adjust some code it work well:
package {{.PkgName}}
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"xxxxx/common/response"
{{.ImportPackages}}
)
func {{.HandlerName}}(ctx *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 := logic.New{{.LogicType}}(r.Context(), ctx)
{{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}})
{{if .HasResp}}response.Response(w, resp, err){{else}}response.Response(w, nil, err){{end}}
}
}
What's the error? and what did you adjust?
As my description that fully copy handle.tpl to internal/handler/xxxhandler.go, I mean as {% raw %}, {% endraw %} in xxxhandler.go , i think these should't appear in xxxhandle.go
I have a commit to adjust that:
https://github.com/CockyCat/portal/commit/29e4c147ba688165ccb2e1d4da1c4fcb29ba4173
Try and see https://pkg.go.dev/text/template
The input text for a template is UTF-8-encoded text in any format. "Actions"--data evaluations or control structures--are delimited by "{{" and "}}"
It's clear that delimited by "{%" and "%}" was not supported because we haven't custom delimiter in goctl.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.