Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
517e0572
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
大约 1 年 前同步成功
通知
344
Star
18155
Fork
5506
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
517e0572
编写于
3月 04, 2021
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmd剔除 初始数据结构转移 修复初始携带apibug
上级
18ef7271
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
117 addition
and
21 deletion
+117
-21
server/api/v1/sys_initdb.go
server/api/v1/sys_initdb.go
+22
-1
server/initialize/router.go
server/initialize/router.go
+2
-3
server/model/sys_initdb.go
server/model/sys_initdb.go
+4
-0
server/router/sys_init.go
server/router/sys_init.go
+0
-1
server/router/sys_initdb.go
server/router/sys_initdb.go
+14
-0
server/service/sys_initdb.go
server/service/sys_initdb.go
+63
-4
server/source/admin.go
server/source/admin.go
+1
-1
server/source/api.go
server/source/api.go
+1
-1
server/source/authorities_menus.go
server/source/authorities_menus.go
+1
-1
server/source/authority.go
server/source/authority.go
+1
-1
server/source/authority_menu.go
server/source/authority_menu.go
+1
-1
server/source/casbin.go
server/source/casbin.go
+1
-1
server/source/data_authorities.go
server/source/data_authorities.go
+1
-1
server/source/dictionary.go
server/source/dictionary.go
+1
-1
server/source/dictionary_details.go
server/source/dictionary_details.go
+1
-1
server/source/file.go
server/source/file.go
+1
-1
server/source/menu.go
server/source/menu.go
+1
-1
server/source/workflow.go
server/source/workflow.go
+1
-1
未找到文件。
server/api/v1/sys_initdb.go
浏览文件 @
517e0572
...
...
@@ -16,7 +16,7 @@ import (
// @Produce application/json
// @Param data body request.InitDB true "初始化数据库参数"
// @Success 200 {string} string "{"code":0,"data":{},"msg":"自动创建数据库成功"}"
// @Router /initdb [post]
// @Router /init
/init
db [post]
func
InitDB
(
c
*
gin
.
Context
)
{
if
global
.
GVA_DB
!=
nil
{
global
.
GVA_LOG
.
Error
(
"非法访问"
)
...
...
@@ -36,3 +36,24 @@ func InitDB(c *gin.Context) {
}
response
.
OkWithData
(
"自动创建数据库成功"
,
c
)
}
// @Tags CheckDB
// @Summary 初始化用户数据库
// @Produce application/json
// @Success 200 {string} string "{"code":0,"data":{},"msg":"探测完成"}"
// @Router /init/checkdb [post]
func
CheckDB
(
c
*
gin
.
Context
)
{
if
global
.
GVA_DB
==
nil
{
global
.
GVA_LOG
.
Info
(
"数据库无需初始化"
)
response
.
OkWithDetailed
(
gin
.
H
{
"needInit"
:
false
,
},
"数据库无需初始化"
,
c
)
return
}
else
{
global
.
GVA_LOG
.
Info
(
"前往初始化数据库"
)
response
.
OkWithDetailed
(
gin
.
H
{
"needInit"
:
true
,
},
"前往初始化数据库"
,
c
)
return
}
}
server/initialize/router.go
浏览文件 @
517e0572
package
initialize
import
(
v1
"gin-vue-admin/api/v1"
_
"gin-vue-admin/docs"
"gin-vue-admin/global"
"gin-vue-admin/middleware"
...
...
@@ -17,12 +16,11 @@ import (
func
Routers
()
*
gin
.
Engine
{
var
Router
=
gin
.
Default
()
Router
.
POST
(
"initdb"
,
v1
.
InitDB
)
Router
.
StaticFS
(
global
.
GVA_CONFIG
.
Local
.
Path
,
http
.
Dir
(
global
.
GVA_CONFIG
.
Local
.
Path
))
// 为用户头像和文件提供静态地址
// Router.Use(middleware.LoadTls()) // 打开就能玩https了
global
.
GVA_LOG
.
Info
(
"use middleware logger"
)
// 跨域
Router
.
Use
(
middleware
.
Cors
())
//Router.Use(middleware.Cors()) // 如需跨域可以打开
global
.
GVA_LOG
.
Info
(
"use middleware cors"
)
Router
.
GET
(
"/swagger/*any"
,
ginSwagger
.
WrapHandler
(
swaggerFiles
.
Handler
))
global
.
GVA_LOG
.
Info
(
"register swagger handler"
)
...
...
@@ -30,6 +28,7 @@ func Routers() *gin.Engine {
PublicGroup
:=
Router
.
Group
(
""
)
{
router
.
InitBaseRouter
(
PublicGroup
)
// 注册基础功能路由 不做鉴权
router
.
InitInitRouter
(
PublicGroup
)
// 自动初始化相关
}
PrivateGroup
:=
Router
.
Group
(
""
)
PrivateGroup
.
Use
(
middleware
.
JWTAuth
())
.
Use
(
middleware
.
CasbinHandler
())
...
...
server/model/sys_initdb.go
浏览文件 @
517e0572
package
model
type
InitDBFunc
interface
{
Init
()
(
err
error
)
}
server/router/sys_init.go
已删除
100644 → 0
浏览文件 @
18ef7271
package
router
server/router/sys_initdb.go
0 → 100644
浏览文件 @
517e0572
package
router
import
(
"gin-vue-admin/api/v1"
"github.com/gin-gonic/gin"
)
func
InitInitRouter
(
Router
*
gin
.
RouterGroup
)
{
ApiRouter
:=
Router
.
Group
(
"init"
)
{
ApiRouter
.
POST
(
"initbd"
,
v1
.
InitDB
)
// 创建Api
ApiRouter
.
POST
(
"checkdb"
,
v1
.
CheckDB
)
// 创建Api
}
}
server/service/sys_initdb.go
浏览文件 @
517e0572
package
service
import
(
"database/sql"
"fmt"
"gin-vue-admin/cmd/source"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/source"
"github.com/spf13/viper"
)
//@author: [songzhibin97](https://github.com/songzhibin97)
//@function: writeConfig
//@description: 回写配置
//@param:
//@return: error
func
writeConfig
(
viper
*
viper
.
Viper
,
conf
map
[
string
]
interface
{})
error
{
for
k
,
v
:=
range
conf
{
viper
.
Set
(
k
,
v
)
}
return
viper
.
WriteConfig
()
}
//@author: [songzhibin97](https://github.com/songzhibin97)
//@function: createTable
//@description: 创建数据库(mysql)
//@param: dsn string, driver string, createSql
//@return: error
func
createTable
(
dsn
string
,
driver
string
,
createSql
string
)
error
{
db
,
err
:=
sql
.
Open
(
driver
,
dsn
)
if
err
!=
nil
{
return
err
}
defer
db
.
Close
()
if
err
=
db
.
Ping
();
err
!=
nil
{
return
err
}
_
,
err
=
db
.
Exec
(
createSql
)
return
err
}
func
initDB
(
InitDBFunctions
...
model
.
InitDBFunc
)
(
err
error
)
{
for
_
,
v
:=
range
InitDBFunctions
{
err
=
v
.
Init
()
if
err
!=
nil
{
return
err
}
}
return
nil
}
//@author: [songzhibin97](https://github.com/songzhibin97)
//@function: InitDB
//@description: 创建数据库并初始化
...
...
@@ -23,7 +68,7 @@ func InitDB(conf request.InitDB) error {
dsn
:=
fmt
.
Sprintf
(
"%s:%s@tcp(%s:%s)/"
,
conf
.
UserName
,
conf
.
Password
,
conf
.
Host
,
conf
.
Port
)
fmt
.
Println
(
dsn
)
createSql
:=
fmt
.
Sprintf
(
"CREATE DATABASE IF NOT EXISTS %s DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;"
,
conf
.
DBName
)
if
err
:=
source
.
C
reateTable
(
dsn
,
"mysql"
,
createSql
);
err
!=
nil
{
if
err
:=
c
reateTable
(
dsn
,
"mysql"
,
createSql
);
err
!=
nil
{
return
err
}
setting
:=
map
[
string
]
interface
{}{
...
...
@@ -32,9 +77,23 @@ func InitDB(conf request.InitDB) error {
"mysql.username"
:
conf
.
UserName
,
"mysql.password"
:
conf
.
Password
,
}
if
err
:=
source
.
WriteConfig
(
global
.
GVA_VP
,
setting
);
err
!=
nil
{
if
err
:=
writeConfig
(
global
.
GVA_VP
,
setting
);
err
!=
nil
{
return
err
}
err
:=
initDB
(
source
.
Admin
,
source
.
Api
,
source
.
AuthorityMenu
,
source
.
Authority
,
source
.
AuthoritiesMenus
,
source
.
Casbin
,
source
.
DataAuthorities
,
source
.
Dictionary
,
source
.
DictionaryDetail
,
source
.
File
,
source
.
BaseMenu
,
source
.
Workflow
)
if
err
!=
nil
{
return
err
}
source
.
InitDB
()
return
nil
}
server/source/admin.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/api.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/authorities_menus.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/authority.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/authority_menu.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/casbin.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/data_authorities.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/dictionary.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/dictionary_details.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/file.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/menu.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
server/source/workflow.go
浏览文件 @
517e0572
package
information
package
source
import
(
"gin-vue-admin/global"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录