go-zero
go-zero copied to clipboard
How to share middleware among multiple services?
Hello, I wonder how to share middleware like JwtBlockList among multiple services.
Given an API file like this, goctl would generate middleware under internal/ directory.
@server(
jwt: Auth
group: user
middleware: JwtBlockList
)
Are there any API syntax could refer to a public reused middleware, like in pkg/middleware/jwtblocklist/
Add the middleware literally in your code.
It is possible to achieve this with template modification.
Goctl template command is extremely helpful goctl template init --home yourprojectpath/alternate.
You can overwrite yourprojectpath/alternate/api/main.tpl and inject your global middleware with server.Use(remote.Middleware). Don't forget to provide import statement and run go mod tidy after generation if required.
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.