Skip to content
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

g.Meta Add middleware to a single address when using canonical routing #4181

Open
yayoyanyue opened this issue Mar 4, 2025 · 2 comments
Open
Assignees
Labels
feature planned This issue/proposal is planned into our next steps.

Comments

@yayoyanyue
Copy link

yayoyanyue commented Mar 4, 2025

Is your feature request related to a problem?

Option Yes

Describe the solution you'd like

规范路由请求:

type CreateTaskReq struct {
	g.Meta    `path:"/create" method:"post" tags:"任务" summary:"新建任务"`
	xxx
}

主函数:

func main() {
	s := g.Server()
	s.Use(
		ghttp.MiddlewareCORS,
		ghttp.MiddlewareHandlerResponse,
		middleware.MiddlewareLog,
	)
	s.Group("/task", func(group *ghttp.RouterGroup) {
		group.Bind(
			task.NewV1(),
		)
	})
	s.Run()
}

Describe alternatives you've considered

需求:
我想给 /task 这个地址下 /task/create 这个路由添加一个鉴权的中间件
希望能在 g.Meta 中有一个 middleware 中间件的数组 就很方便了
获取有其他的解决办法

Additional

No response

@Issues-translate-bot Issues-translate-bot changed the title g.Meta 使用规范路由的时候 给单个地址添加中间件 g.Meta Add middleware to a single address when using canonical routing Mar 4, 2025
@gqcn
Copy link
Member

gqcn commented Mar 4, 2025

其实有好办法,在元数据中加个标识,通过统一的中间件读取这个标识做判断。我搞个example和文档。

@gqcn gqcn added the planned This issue/proposal is planned into our next steps. label Mar 4, 2025
@gqcn gqcn self-assigned this Mar 4, 2025
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


In fact, there is a good way to add an identifier to the metadata and use unified middleware to read this identifier to make judgments. I'll make an example and documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

No branches or pull requests

3 participants