go-zero
go-zero copied to clipboard
I hope to support more parameter passing to achieve more flexible automatic generation.
this place
https://github.com/zeromicro/go-zero/blob/b61e36445851aefecb65138fd547ec83926c7e97/tools/goctl/api/gogen/genhandlers.go#L34-L55
user.api
@server(
group: user
prefix: api/user
)
service aif-api {
@doc(
summary: "Push SMS"
diy1: "123"
)
@handler SmsPushHandler
post /sms (SmsReq)
@doc(
summary: "User Login"
)
@handler LoginHandler
post /login (UserLoginReq) returns (UserLoginRes)
}
My handler.tpl
package {{.PkgName}}
import (
"net/http"
"aif/internal/ai"
{{.ImportPackages}}
"github.com/zeromicro/go-zero/rest/httpx"
)
// {{.HandlerName}}
// @Summary User login
// @Description
// @Tags {{.PkgName}}
// @Accept json
// @Produce json
{{if .HasRequest}}// @Param params query types.{{.RequestType}} true "params" {{end}}
{{if .HasResp}}// @Success 200 {object} ai.H{data=ai.ListData{rows=[]types.Attribute}}{{else}}// @Success 200 {object} ai.H{{end}}
// @Router /api/{{.PkgName}}/{{.HandlerName}} [get]
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 err != nil {
httpx.OkJsonCtx(r.Context(), w, ai.NewE(err))
} else {
{{if .HasResp}}httpx.OkJsonCtx(r.Context(), w, ai.Data(resp)){{else}}httpx.OkJsonCtx(r.Context(), w, ai.Success()){{end}}
}
}
}
I hope to generate Swagger annotation documentation here, but there is a lack of route
@doc
related data.
@kevwan
Bot detected the issue body's language is not English, translate it automatically. π―ππ»π§βπ€βπ§π«π§πΏβπ€βπ§π»π©πΎβπ€βπ¨πΏπ¬πΏ
@kevwan
At present, the api file parses with annotation information, which I can inject into the template variable, and you can use this variable by customizing the template
At present, the api file parses with annotation information, which I can inject into the template variable, and you can use this variable by customizing the template
@anqiansong Thank you for your reply and hope to support this feature as soon as possible.
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.