go-zero
go-zero copied to clipboard
because of import cycle, middleware cant use ServiceContext,is there a better way to define the middleware?
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.
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?
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
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.