Skip to content

Commit a8b01b6

Browse files
author
pixel
committed
开启初始化配置 暂时修改为 配置文件控制
1 parent 513259f commit a8b01b6

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

server/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ system:
5252
env: 'public' # Change to "develop" to skip authentication for development mode
5353
addr: 8888
5454
db-type: "mysql" # support mysql/sqlite
55+
need-init-data: false
5556

5657
# captcha configuration
5758
captcha:

server/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type System struct {
1818
Env string `mapstructure:"env" json:"env" yaml:"env"`
1919
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"`
2020
DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"`
21+
NeedInitData bool `mapstructure:"need-init-data" json:"needInitData" yaml:"need-init-data"`
2122
}
2223

2324
type JWT struct {

server/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"gin-vue-admin/core"
55
"gin-vue-admin/global"
6+
"gin-vue-admin/gva/init_data"
7+
68
//"gin-vue-admin/gva/init_data"
79
"gin-vue-admin/initialize"
810
//"runtime"
@@ -25,7 +27,9 @@ func main() {
2527
initialize.Mysql()
2628
}
2729
initialize.DBTables()
28-
//init_data.InitData() // 打开注释即可初始化数据 使用过后一定要再次注释或删除
30+
if global.GVA_CONFIG.System.NeedInitData {
31+
init_data.InitData() // 通过配置文件初始化数据 默认为 false 首次运行需要将 ./config.yaml中 system下的 need-init-data 修改为true
32+
}
2933
// 程序结束前关闭数据库链接
3034
db, _ := global.GVA_DB.DB()
3135
defer db.Close()

0 commit comments

Comments
 (0)