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

fix: goctl genhandler duplicate rest/httpx & template import custom #2152

Merged
merged 1 commit into from Jul 19, 2022

Conversation

smithyj
Copy link
Contributor

@smithyj smithyj commented Jul 15, 2022

fix: goctl genhandler duplicate rest/httpx & goctl genhandler template support custom import httpx package

Reason:
1、在 handler 层,我对 httpx 包进行了再次封装
2、在某些情况下,我需要控制 httpx 包的导入
3、goctl 1.3.9 会出现两个 rest/httpx 包

Example:

# handler.tpl
package {{.PkgName}}

import (
	"net/http"

	"appservice/pkg/resultx"
	{{.ImportPackages}}
        {{if .HasRequest}}
	{{.ImportHttpxPackage}}
        {{end}}
)

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 {
			resultx.HttpParamErrorResult(r, w, err)
			return
		}

		{{end}}l := {{.LogicName}}.New{{.LogicType}}(r.Context(), svcCtx)
		{{if .HasResp}}resp, {{end}}err := l.{{.Call}}({{if .HasRequest}}&req{{end}})

		{{if .HasResp}}resultx.HttpResult(r, w, resp, err){{else}}resultx.HttpResult(r, w, nil, err){{end}}

	}
}

@smithyj
Copy link
Contributor Author

smithyj commented Jul 16, 2022

@anqiansong

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@an Qian send

@smithyj
Copy link
Contributor Author

smithyj commented Jul 16, 2022

@kevwan

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@kevwan

@kevwan kevwan requested a review from kesonan July 19, 2022 14:53
Copy link
Collaborator

@kesonan kesonan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevwan kevwan merged commit bc85eaa into zeromicro:master Jul 19, 2022
@jsonMark
Copy link
Contributor

这个情况我也遇到了。我们是同微信交互。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I also encountered this situation. We are interacting with WeChat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants