diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4c2f890..e58ba3e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -21,5 +21,7 @@ jobs: - name: Install run: go install github.com/swaggo/swag/cmd/swag@latest + # 生成swag信息 + # build项目 - name: Build run: swag init && go build diff --git a/README.md b/README.md index 008b64f..51a73dd 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,7 @@ 基于属性的权限验证(ABAC,Attribute-Based Access Control)的微服务,为其他业务服务提供权限认证。 -## 参考 -https://github.com/marmotedu/iam/tree/v1.0.0 -- [go swagg api文档](https://github.com/swaggo/swag/blob/master/README_zh-CN.md#%E5%A3%B0%E6%98%8E%E5%BC%8F%E6%B3%A8%E9%87%8A%E6%A0%BC%E5%BC%8F) ## 快速开始 @@ -17,6 +14,22 @@ https://github.com/marmotedu/iam/tree/v1.0.0 air ``` -- 查看接口文档 + > air启动后需要过一段时间才可以终止程序(立即`CTRL+C`后,程序可能仍然运行)。 + +- 获取/查看接口文档 + + 拉取项目后,安装[go swag](https://github.com/swaggo/gin-swagger)组件,执行以下命令生成swag文档。 + + ```sh + swag init + ``` + + 然后可以**在debug模式下**前往http:///swagger/index.html查看。 + + + +## 参考 + +- [企业级的 Go 语言实战项目:认证和授权系统](https://github.com/marmotedu/iam/tree/v1.0.0) -跑起项目后,前往http:///swagger/index.html查看。 +- [go swag api文档](https://github.com/swaggo/swag/blob/master/README_zh-CN.md#%E5%A3%B0%E6%98%8E%E5%BC%8F%E6%B3%A8%E9%87%8A%E6%A0%BC%E5%BC%8F) diff --git a/router/init.go b/router/init.go index 26cc4f8..f910365 100644 --- a/router/init.go +++ b/router/init.go @@ -5,9 +5,10 @@ import ( "auth-server/config" "auth-server/docs" "auth-server/middleware" + "strconv" + swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" - "strconv" "github.com/gin-gonic/contrib/sessions" @@ -29,7 +30,10 @@ func InitRouter() { engine := gin.New() engine.Use(gin.Recovery()) - engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + if config.DebugMode { + engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + } + docs.SwaggerInfo.BasePath = "/api/v1" // session 设置 @@ -46,11 +50,11 @@ func InitRouter() { // 登陆认证相关路由 authRouterGroup := engine.Group("/auth") authRouter(authRouterGroup) - // 用户登陆 - userRouterGroup := engine.Group("/api/v1") - userRouterGroup.Use(middleware.SessionAuth()) + // 业务路由 + serviceRouterGroup := engine.Group("/api/v1") + serviceRouterGroup.Use(middleware.SessionAuth()) + userRouter(serviceRouterGroup) - userRouter(userRouterGroup) port := config.ServerPort runParams := config.ServerHost + ":" + strconv.Itoa(port) log.Println("master server at ", runParams)