Skip to content

Commit

Permalink
feat: update github release action & update README
Browse files Browse the repository at this point in the history
  • Loading branch information
afzw committed Apr 28, 2024
1 parent a905fc5 commit e07c91a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go
name: Release

on:
push:
branches: ["dev", "swagger-fzw"]
branches: ["dev"]

jobs:
build:
Expand All @@ -20,4 +20,4 @@ jobs:

# build项目
- name: Build
run: go build --tags=server
run: go build --tags=production
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@
基于属性的权限验证(ABAC,Attribute-Based Access Control)的微服务,为其他业务服务提供权限认证。



## 快速开始

- 启动项目-开发(含热加载)
### 编译模式

```sh
air
```
- dev模式

> air启动后需要过一段时间才可以终止程序(立即`CTRL+C`后,程序可能仍然运行)。
dev模式,默认开启swagger ui和debug模式

- 获取/查看接口文档
```sh
go run -tags=dev main.go
```

- production模式

production模式,默认不开启swagger ui,选择性开启debug模式

```sh
go run -tags=production main.go
```

### swagger接口文档服务(dev编译模式)

拉取项目后,安装[go swag](https://github.com/swaggo/gin-swagger)组件,根据以下提示生成swag文档并查看。

```sh
# generate documentation for auth endpoint.
# (debug mode) after generation, open http://BASEURL/swagger/auth/index.html to check.
Expand All @@ -28,9 +37,18 @@
# generate documentation for api/v1 endpoint.
# (debug mode) after generation, open http://BASEURL/swagger/v1/index.html to check.
swag i -g v1.go -dir router,api/v1 --instanceName v1 --pd

```


### [尚未完成]实时加载

(暂时缺少对不同编译模式的支持)

```sh
air
```

> air启动后需要过一段时间才可以终止程序(立即`CTRL+C`后,程序可能仍然运行)。

## 参考
Expand Down
12 changes: 6 additions & 6 deletions loader/engine_dev.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
//go:build dev

// dev模式,默认开启swagger ui和debug模式

package loader

import (
"auth-server/config"
_ "auth-server/docs"
"auth-server/middleware"
"auth-server/router"

"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
Expand All @@ -27,12 +30,9 @@ func InitEngine() *gin.Engine {
// 初始化引擎路由
engine = router.InitRouter(engine)

// debug模式,
if config.DebugMode {
// 开启swagger ui
engine.GET("/swagger/auth/*any", ginSwagger.WrapHandler(swaggerFiles.NewHandler(), ginSwagger.InstanceName("auth")))
engine.GET("/swagger/v1/*any", ginSwagger.WrapHandler(swaggerFiles.NewHandler(), ginSwagger.InstanceName("v1")))
}
// 开启swagger ui
engine.GET("/swagger/auth/*any", ginSwagger.WrapHandler(swaggerFiles.NewHandler(), ginSwagger.InstanceName("auth")))
engine.GET("/swagger/v1/*any", ginSwagger.WrapHandler(swaggerFiles.NewHandler(), ginSwagger.InstanceName("v1")))

return engine
}
5 changes: 4 additions & 1 deletion loader/engine_server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//go:build server
//go:build production

// production模式,默认不开启swagger ui,选择性开启debug模式

package loader

import (
"auth-server/config"
"auth-server/middleware"
"auth-server/router"

"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
Expand Down

0 comments on commit e07c91a

Please sign in to comment.