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

feat(goctl): update api handler comment during generation #3873

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WqyJh
Copy link
Contributor

@WqyJh WqyJh commented Jan 25, 2024

Support handler comments and update handler comments during generation.

Define swagger document for handler in .api files.

@server(
	group: user
    prefix: /api/v1/user
    jwt: JwtAuth
)
service api {
    // UserSelf godoc
    // @Summary      查询用户信息
    // @Description  查询用户信息
    // @Tags         user
    // @Security     ApiKeyAuth
    // @Accept       json
    // @Produce      json
    // @Param        client   header      string  true  "当前设备类型: android/ios"
    // @Success      200    {object}   types.DataResponse{data=types.UserSelfReply}
    // @Router       /api/v1/user/self [get]
    @handler UserSelf
    get /self (UserSelfReq) returns (UserSelfReply)
}

The document defined would be rendered on handler. And if you update the api file, and regenerate the handler, handler will also be updated.

// UserSelf godoc
//	@Summary		查询用户信息
//	@Description	查询用户信息
//	@Tags			user
//	@Security		ApiKeyAuth
//	@Accept			json
//	@Produce		json
//	@Param			client		header		string	true	"当前设备类型: android/ios"
//	@Success		200			{object}	types.DataResponse{data=types.UserSelfReply}
//	@Router			/api/v1/user/self [get]
func UserSelfHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.UserSelfReq
		if err := httpz.Parse(r, &req); err != nil {
			httpz.ErrorLog(r.Context(), w, err)
			return
		}

		logc.Infow(r.Context(), "UserSelfHandler", logc.Field("req", &req))

		l := user.NewUserSelfLogic(r.Context(), svcCtx)
		resp, err := l.UserSelf(&req)
		if err != nil {
			httpz.Error(w, err)
			logc.Infow(r.Context(), "UserSelfHandler error", logc.Field("error", err))
		} else {
			httpz.OkJson(w, resp)
			logc.Infow(r.Context(), "UserSelfHandler success", logc.Field("resp", resp))
		}
	}
}

More details: https://github.com/WqyJh/goctl-gogen.
Related to #2464

@WqyJh
Copy link
Contributor Author

WqyJh commented Feb 21, 2024

Any progress?

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

1 participant