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

[Feature]: Api白名单 #1748

Closed
Ruy5 opened this issue May 18, 2024 · 2 comments
Closed

[Feature]: Api白名单 #1748

Ruy5 opened this issue May 18, 2024 · 2 comments

Comments

@Ruy5
Copy link

Ruy5 commented May 18, 2024

功能描述以及必要性描述

如果我希望部分接口,无需登录(不携带x-token)就能访问到该如何设置

建议和方案

No response

@juneyx
Copy link
Contributor

juneyx commented May 18, 2024

router/{package_name}/{struct_name}.go中可以按需配置接口白名单

比如说demo包中有个功能模块叫demo1,那就编辑router/demo/demo1.go

// InitDemo1Router 初始化demo1表 路由信息
func (s *DemoRouter) InitDemo1Router(Router *gin.RouterGroup, PublicRouter *gin.RouterGroup) {
	demo1Router := Router.Group("demo1").Use(middleware.OperationRecord())
	demo1RouterWithoutRecord := Router.Group("demo1")
	demo1RouterWithoutAuth := PublicRouter.Group("demo1")

        // 将接口逻辑提前在Demo1Api中写好
	var demo1Api = v1.ApiGroupApp.DemoApiGroup.Demo1Api
	{
                // 通过demo1Route绑定需要记录操作日志的接口
		demo1Router.POST("create", demo1Api.Create)
		demo1Router.DELETE("delete", demo1Api.Delete)
		demo1Router.DELETE("deleteByIds", demo1Api.DeleteByIds)
		demo1Router.PUT("update", demo1Api.Update) 
	}
	{
                // 通过demo1RouterWithoutRecord绑定不需要记录日志的接口
		demo1RouterWithoutRecord.GET("find", demo1Api.Find) 
		demo1RouterWithoutRecord.GET("getList", demo1Api.GetList)
	}
	{
                // 通过demo1RouterWithoutAuth绑定不需要鉴权的接口(即白名单接口)
		demo1RouterWithoutAuth.GET("getPublic", demo1Api.GetPublic)
		demo1RouterWithoutAuth.POST("whitePost", demo1Api.PostData)
		demo1RouterWithoutAuth.GET("whiteGet", demo1Api.GetData)
	}
}

@pixelmaxQm
Copy link
Collaborator

目前有无需配置的功能接口,已经自动化提供了。感谢 juneyx 给出解释

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants