Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add projectPkg and servicePkg parameters to gen api template(go module) #3786

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

6xiaowu9
Copy link

@6xiaowu9 6xiaowu9 commented Dec 12, 2023

Issue: #3785

In actual application scenarios, we should allow users to use the two parameters projectPkg and rootPkg when customizing templates.

add parameters to template:

  • projectPkg
  • servicePkg

handler example:

package {{.PkgName}}

import (
        "net/http"

        "github.com/zeromicro/go-zero/rest/httpx"
        "{{.ServicePkg}}/internal/response"
        {{.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.ErrorCtx(r.Context(), w, err)
                        return
                }

                {{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx)
                {{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}}
        }
}

other example:

package {{.pkgName}}

import (
        "{{.projectPkg}}/xxx"
        "{{.servicePkg}}/xxx"
)

just handler is {{.ServicePkg}} and {{.ProjectPkg}}

@6xiaowu9
Copy link
Author

@kevwan Hi, I hope you can help me see if this change is reasonable and correct.

@kevwan kevwan added the area/goctl Categorizes issue or PR as related to goctl. label Dec 16, 2023
@kevwan kevwan force-pushed the feature/gen-api-template-add-rootPkg branch from b1c1854 to 1385184 Compare December 17, 2023 05:18
@6xiaowu9 6xiaowu9 changed the title feature: add rootpkg parameters to gen api template feature: add projectPkg and rootPkg parameters to gen api template Dec 18, 2023
@kesonan
Copy link
Collaborator

kesonan commented Dec 18, 2023

Go module variable has already open for go template on api/rpc generating. pls see #3798

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b6f00a5) 94.69% compared to head (16443a1) 94.67%.

❗ Current head 16443a1 differs from pull request most recent head 6058d3c. Consider uploading reports for the commit 6058d3c to get more accurate results

Additional details and impacted files

see 7 files with indirect coverage changes

@6xiaowu9 6xiaowu9 changed the title feature: add projectPkg and rootPkg parameters to gen api template feature: add projectPkg and servicePkg parameters to gen api template(go module) Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/goctl Categorizes issue or PR as related to goctl.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants