go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

because of import cycle, middleware cant use ServiceContext,is there a better way to define the middleware?

Open ethantsien opened this issue 2 years ago • 3 comments

I think ServiceContext can not import any modules of its own project except Config, so that it can play its best role. For example, as I mentioned in the title, use it in middleware. Therefore, the initialization of middleware should be placed in routes, not in ServiceContext. In ServiceContext, only external services should be initialized.

ethantsien avatar Jul 24 '23 18:07 ethantsien

Very good advice, but the previous design idea was to be able to replace the middleware in serviceContext, so the definition is in there. Can you provider a demo to see which work better?

re-dylan avatar Jul 26 '23 15:07 re-dylan

routes.go and types.go should not be modified, because a lot of content here is often adjusted in actual business, once modified, it cannot be automatically generated, so I think it should not be designed to replace middleware in ServiceContext , just configure in the api file and regenerate routes.go. A few days ago, I forked and modified it to initialize middleware in routes and pass in ServiceContext in initialization middleware.

https://github.com/relxet/go-zero

ethantsien avatar Jul 26 '23 17:07 ethantsien

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 30 '24 01:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Oct 30 '24 02:10 github-actions[bot]