Open smithyj opened 1 year ago
@kevwan
In what scenarios do you need to use this?
You can add middlewares in your AddRoute
statements.
But would you please give the concrete scenarios that you want this feature?
According to the current goctl pattern, I have to repeat the definition of the same group syntax block as shown in the example below, but the goctl idea plugin shows an error.
I encountered an issue while trying to repeat the definition of the group syntax block as indicated in the example, and the goctl idea plugin flagged it as an error.
@server (
prefix: /captcha/v1
group: generate
)
service captcha {
@doc "生成图片验证码"
@handler GenerateImage
get /generate/image returns (GenerateImageResponse)
}
@server (
prefix: /captcha/v1
group: generate
middleware: VerifyMiddleware
)
service captcha {
@doc "生成短信验证码"
@handler GenerateSms
post /generate/sms (GenerateSmsRequest) returns (GenerateSmsResponse)
@doc "生成邮箱验证码"
@handler GenerateEmail
post /generate/email (GenerateEmailRequest) returns (GenerateEmailResponse)
@doc "生成滑动验证码"
@handler GenerateSlide
post /generate/slide (GenerateSlideRequest) returns (GenerateSlideResponse)
}
I believe that adding middleware configuration at the handler level would make the business definition more flexible, reduce code redundancy, and also meet the requirements of the idea plugin.
@server (
prefix: /captcha/v1
group: generate
)
service captcha {
@doc "生成图片验证码"
@handler GenerateImage
get /generate/image returns (GenerateImageResponse)
@doc "生成短信验证码"
@handler GenerateSms
@middleware: VerifyMiddleware
post /generate/sms (GenerateSmsRequest) returns (GenerateSmsResponse)
@doc "生成邮箱验证码"
@handler GenerateEmail
@middleware: VerifyMiddleware
post /generate/email (GenerateEmailRequest) returns (GenerateEmailResponse)
@doc "生成滑动验证码"
@handler GenerateSlide
@middleware: VerifyMiddleware
post /generate/slide (GenerateSlideRequest) returns (GenerateSlideResponse)
}
In fact, mainstream web frameworks in any language currently support global-level middleware, group-level middleware, and handler-level middleware. I hope this requirement can be included in the development plan as it will greatly benefit developers.
@kevwan
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@kevwan
I think this approach is sufficient, if the idea plugin prompts an error, then it should be possible to fix it for the idea plugin
@server ( prefix: /captcha/v1 group: generate ) service captcha { @doc "生成图片验证码" @handler GenerateImage get /generate/image returns (GenerateImageResponse) }
@server ( prefix: /captcha/v1 group: generate middleware: VerifyMiddleware ) service captcha { @doc "生成短信验证码" @handler GenerateSms post /generate/sms (GenerateSmsRequest) returns (GenerateSmsResponse)
@doc "生成邮箱验证码"
@handler GenerateEmail
post /generate/email (GenerateEmailRequest) returns (GenerateEmailResponse)
@doc "生成滑动验证码"
@handler GenerateSlide
post /generate/slide (GenerateSlideRequest) returns (GenerateSlideResponse)
}
@kevwan @Mikaelemmmm 如下所示,这种需求下,就很有必要推出 handler 级别 middleware
@server (
prefix: /account/v1
group: account
middleware: AuthMiddleware
)
service account {
@doc "获取用户信息"
@handler GetInfo
get /account/info returns (AccountInfoResponse)
@doc "修改密码"
@handler ModifyPassword
@middleware: VerifyCatpchaMiddleware
patch /account/password (ModifyPasswordRequest) returns (ModifyPasswordResponse)
}
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@kevwan @Mikaelemmmm As shown below, under this requirement, it is necessary to introduce handler level middleware
@server (
prefix: /account/v1
group: account
middleware: Auth Middleware
)
service account {
@doc "Get user information"
@handler GetInfo
get /account/info returns (AccountInfoResponse)
@doc "Change Password"
@handler ModifyPassword
@middleware: VerifyCatpchaMiddleware
patch /account/password (ModifyPasswordRequest) returns (ModifyPasswordResponse)
}
@kevwan @Mikaelemmmm
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@kevwan @Mikaelemmmm
This issue is stale because it has been open for 30 days with no activity.
Have you considered adding
@middleware
at the handler level in goctl?