Skip to content

Commit f35a808

Browse files
committed
perf ⚡ 优化配置文件加载
1 parent b8ab383 commit f35a808

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

cmd/api/server.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ func setup() {
5858
// 注入配置扩展项
5959
config.ExtendConfig = &ext.ExtConfig
6060
//1. 读取配置
61-
config.Setup(file.NewSource, file.WithPath(configYml))
62-
go config.Watch()
61+
config.Setup(file.NewSource(file.WithPath(configYml)))
6362
//2. 设置日志
6463
sdk.Runtime.SetLogger(
6564
logger.SetupLogger(
@@ -70,8 +69,6 @@ func setup() {
7069
//3. 初始化数据库链接
7170
database.Setup()
7271

73-
//list := sdk.Runtime.GetDb()
74-
//list["*"]
7572
//4. 设置缓存
7673
cacheAdapter, err := config.CacheConfig.Setup()
7774
if err != nil {
@@ -113,8 +110,6 @@ func setup() {
113110
}
114111

115112
func run() error {
116-
defer config.Stop()
117-
118113
if config.ApplicationConfig.Mode == pkg.ModeProd.String() {
119114
gin.SetMode(gin.ReleaseMode)
120115
}

cmd/config/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func init() {
2727
}
2828

2929
func run() {
30-
config.Setup(file.NewSource, file.WithPath(configYml))
30+
config.Setup(file.NewSource(file.WithPath(configYml)))
3131

3232
application, errs := json.MarshalIndent(config.ApplicationConfig, "", " ") //转换成JSON返回的是byte[]
3333
if errs != nil {

cmd/migrate/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func run() {
4949
if !generate {
5050
fmt.Println(`start init`)
5151
//1. 读取配置
52-
config.Setup(file.NewSource, file.WithPath(configYml))
52+
config.Setup(file.NewSource(file.WithPath(configYml)))
5353
//2. 设置日志
5454
sdk.Runtime.SetLogger(
5555
logger.SetupLogger(

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/bytedance/go-tagexpr/v2 v2.7.10
1010
github.com/casbin/casbin/v2 v2.25.1
1111
github.com/gin-gonic/gin v1.7.1
12-
github.com/go-admin-team/go-admin-core v1.3.5-rc.3.0.20210609055649-3acdd6f47eab
13-
github.com/go-admin-team/go-admin-core/sdk v1.3.0-rc.3.0.20210609055649-3acdd6f47eab
12+
github.com/go-admin-team/go-admin-core v1.3.5-rc.3.0.20210609062350-5aeb6bd49b09
13+
github.com/go-admin-team/go-admin-core/sdk v1.3.0-rc.3.0.20210609082125-a317acc34456
1414
github.com/google/uuid v1.2.0
1515
github.com/mssola/user_agent v0.5.2
1616
github.com/opentracing/opentracing-go v1.1.0

0 commit comments

Comments
 (0)