-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rest.Route add AtDoc field for struct #4573
base: master
Are you sure you want to change the base?
Conversation
Why do you need |
We can use this annotation to label, group, and perform routing specific operations, such as setting the nickname of the route/user/list as the user query interface, and setting its parent route. This way, we can load the routing information into the database when the service starts, and then make use of this routing information, such as setting permission roles. When we assign interface permissions to a certain role, an interface is needed, and users querying such nicknames are more expressive than/user/list, knowing what interface it is at a glance. Similar to the situation shown in the picture below, it is impossible for us to manually label each interface. This way, two or three interfaces are sufficient, while hundreds of interfaces would be exhausting 我们可以使用这个注释来给路由打标签,分组,做一些特定于路由的操作,比如 可以设置 路由 /user/list 昵称为 用户查询接口,还可以给该路由设置其父路由,这样我们可以在服务启动的时候加载这些路由信息到数据库,然后对这些路由信息进行一些利用,比如权限角色设置。当我们给某个角色分配接口权限的时候,需要接口,那 用户查询 这样的昵称比 /user/list 更有表现力,一看就知道是什么接口。类似于下面图片的情况,不可能我们每个接口手动的给其标注一下,这样两三个可以,几百个接口就累死人了 |
go-zero has already supported route group, middlewares, I think it can help you implementing this functions, I don't recommend adding these annotations, How do you think so? @kevwan |
Is there any way to collect custom information on routes, such as metadata |
I think you can only implement from comments. |
rest.Route add AtDoc field for struct
给rest.Route{}结构体添加一个 AtDoc 的map[string]string 属性字段,goctl 生成代码时,会给这个字段赋值。
这样可以根据给定的注释开发出更多复杂的关于路由的功能