mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-20 17:57:54 +00:00
Fix problems modifying personal information,Upgrade route configuration format
This commit is contained in:
+1
-1
@@ -89,7 +89,7 @@ func InsertDept(c *gin.Context) {
|
||||
// @Security Bearer
|
||||
func UpdateDept(c *gin.Context) {
|
||||
var data models.Dept
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
err := c.BindJSON(&data)
|
||||
tools.HasError(err, "", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.DeptId)
|
||||
|
||||
@@ -172,7 +172,7 @@ func InsertSysUser(c *gin.Context) {
|
||||
// @Router /api/v1/sysuser/{userId} [put]
|
||||
func UpdateSysUser(c *gin.Context) {
|
||||
var data models.SysUser
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
err := c.Bind(&data)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.UserId)
|
||||
|
||||
+17
-6
@@ -18,6 +18,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
|
||||
var (
|
||||
config string
|
||||
port string
|
||||
@@ -55,16 +57,25 @@ func setup() {
|
||||
tools.InitLogger()
|
||||
//3. 初始化数据库链接
|
||||
database.Setup()
|
||||
//4. 设置gin mode
|
||||
if viper.GetString("settings.application.mode") == string(tools.ModeProd) {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func run() error {
|
||||
if mode != "" {
|
||||
config2.SetConfig(config, "settings.application.mode", mode)
|
||||
}
|
||||
if viper.GetString("settings.application.mode") == string(tools.ModeProd) {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
r := router.InitRouter()
|
||||
|
||||
defer database.Eloquent.Close()
|
||||
if port != "" {
|
||||
config2.SetConfig(config, "settings.application.port", port)
|
||||
}
|
||||
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: config2.ApplicationConfig.Host + ":" + config2.ApplicationConfig.Port,
|
||||
@@ -79,8 +90,8 @@ func run() error {
|
||||
}()
|
||||
content, _ := ioutil.ReadFile("./static/go-admin.txt")
|
||||
log.Println(string(content))
|
||||
log.Println("Server Run http://127.0.0.1:"+config2.ApplicationConfig.Port+"/")
|
||||
log.Println("Swagger URL http://127.0.0.1:"+config2.ApplicationConfig.Port+"/swagger/index.html")
|
||||
log.Println("Server Run http://127.0.0.1:" + config2.ApplicationConfig.Port + "/")
|
||||
log.Println("Swagger URL http://127.0.0.1:" + config2.ApplicationConfig.Port + "/swagger/index.html")
|
||||
|
||||
log.Println("Enter Control + C Shutdown Server")
|
||||
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
|
||||
|
||||
+1
-5
@@ -30,7 +30,7 @@ func Setup() {
|
||||
Username = config.DatabaseConfig.Username
|
||||
Password = config.DatabaseConfig.Password
|
||||
|
||||
if DbType != "mysql" && DbType != "sqlite3" {
|
||||
if DbType != "mysql" {
|
||||
log.Println("db type unknow")
|
||||
}
|
||||
var err error
|
||||
@@ -44,10 +44,6 @@ func Setup() {
|
||||
db = new(Mysql)
|
||||
Eloquent, err = db.Open(DbType, conn)
|
||||
|
||||
} else if DbType == "sqlite3" {
|
||||
db = new(SqlLite)
|
||||
Eloquent, err = db.Open(DbType, Host)
|
||||
|
||||
} else {
|
||||
panic("db type unknow")
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2020-04-29 23:00:58.67458 +0800 CST m=+0.080406457
|
||||
// 2020-05-25 21:14:52.220986 +0800 CST m=+0.139814492
|
||||
|
||||
package docs
|
||||
|
||||
@@ -510,9 +510,9 @@ var doc = `{
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"字典数据"
|
||||
"配置"
|
||||
],
|
||||
"summary": "添加字典数据",
|
||||
"summary": "添加配置",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "data",
|
||||
@@ -521,7 +521,7 @@ var doc = `{
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/models.DictType"
|
||||
"$ref": "#/definitions/models.SysConfig"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
+3
-3
@@ -492,9 +492,9 @@
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"字典数据"
|
||||
"配置"
|
||||
],
|
||||
"summary": "添加字典数据",
|
||||
"summary": "添加配置",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "data",
|
||||
@@ -503,7 +503,7 @@
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/models.DictType"
|
||||
"$ref": "#/definitions/models.SysConfig"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
+3
-3
@@ -763,7 +763,7 @@ paths:
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.DictType'
|
||||
$ref: '#/definitions/models.SysConfig'
|
||||
type: object
|
||||
responses:
|
||||
"200":
|
||||
@@ -772,9 +772,9 @@ paths:
|
||||
type: string
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: 添加字典数据
|
||||
summary: 添加配置
|
||||
tags:
|
||||
- 字典数据
|
||||
- 配置
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/tools/app"
|
||||
)
|
||||
|
||||
func HelloGoAdmin(c *gin.Context) {
|
||||
app.OK(c,"欢迎使用go-admin 中后台脚手架","")
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
_ "time"
|
||||
@@ -188,11 +189,17 @@ func (e *Dept) Update(id int) (update Dept, err error) {
|
||||
}
|
||||
e.DeptPath = deptPath
|
||||
|
||||
if e.DeptPath != "" && e.DeptPath != update.DeptPath {
|
||||
return update, errors.New("上级部门不允许修改!")
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ package models
|
||||
import (
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Login struct {
|
||||
@@ -18,23 +16,14 @@ func (u *Login) GetUser() (user SysUser, role SysRole, e error) {
|
||||
|
||||
e = orm.Eloquent.Table("sys_user").Where("username = ? ", u.Username).Find(&user).Error
|
||||
if e != nil {
|
||||
if strings.Contains(e.Error(), "record not found") {
|
||||
tools.HasError(e, "账号或密码错误(代码204)", 500)
|
||||
}
|
||||
log.Print(e)
|
||||
return
|
||||
}
|
||||
_, e = tools.CompareHashAndPassword(user.Password, u.Password)
|
||||
if e != nil {
|
||||
if strings.Contains(e.Error(), "hashedPassword is not the hash of the given password") {
|
||||
tools.HasError(e, "账号或密码错误(代码201)", 500)
|
||||
}
|
||||
log.Print(e)
|
||||
return
|
||||
}
|
||||
e = orm.Eloquent.Table("sys_role").Where("role_id = ? ", user.RoleId).First(&role).Error
|
||||
if e != nil {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
return
|
||||
|
||||
+6
-5
@@ -120,6 +120,7 @@ func (e *SysUser) Get() (SysUserView SysUserView, err error) {
|
||||
if err = table.First(&SysUserView).Error; err != nil {
|
||||
return
|
||||
}
|
||||
SysUserView.Password = ""
|
||||
return
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, erro
|
||||
// 数据权限控制
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope("sys_user", table)
|
||||
table, err := dataPermission.GetDataScope("sys_user", table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@@ -198,10 +199,10 @@ func (e SysUser) Insert() (id int, err error) {
|
||||
|
||||
//修改
|
||||
func (e *SysUser) Update(id int) (update SysUser, err error) {
|
||||
if err = e.Encrypt(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//if err = e.Encrypt(); err != nil {
|
||||
// return
|
||||
//}
|
||||
e.Password = ""
|
||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/pkg/jwtauth"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
// 路由示例
|
||||
func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {
|
||||
|
||||
// 无需认证的路由
|
||||
examplesNoCheckRoleRouter(r)
|
||||
// 需要认证的路由
|
||||
examplesCheckRoleRouter(r, authMiddleware)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// 无需认证的路由示例
|
||||
func examplesNoCheckRoleRouter(r *gin.Engine) {
|
||||
|
||||
//v1 := r.Group("/api/v1")
|
||||
//v1.GET("/examples/list", examples.apis)
|
||||
|
||||
}
|
||||
|
||||
// 需要认证的路由示例
|
||||
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
|
||||
|
||||
//v1auth := r.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
//{
|
||||
// v1auth.GET("/examples/list", examples.apis)
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
+14
-185
@@ -2,207 +2,36 @@ package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
log2 "go-admin/apis/log"
|
||||
"go-admin/apis/monitor"
|
||||
"go-admin/apis/system"
|
||||
"go-admin/apis/system/dict"
|
||||
. "go-admin/apis/tools"
|
||||
_ "go-admin/docs"
|
||||
"go-admin/handler"
|
||||
"go-admin/handler/sd"
|
||||
"go-admin/middleware"
|
||||
_ "go-admin/pkg/jwtauth"
|
||||
"log"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
func InitRouter() *gin.Engine {
|
||||
|
||||
r := gin.New()
|
||||
// 日志处理
|
||||
r.Use(middleware.LoggerToFile())
|
||||
// 自定义错误处理
|
||||
r.Use(middleware.CustomError)
|
||||
// NoCache is a middleware function that appends headers
|
||||
r.Use(middleware.NoCache)
|
||||
// 跨域处理
|
||||
r.Use(middleware.Options)
|
||||
// Secure is a middleware function that appends security
|
||||
r.Use(middleware.Secure)
|
||||
// Set X-Request-Id header
|
||||
r.Use(middleware.RequestId())
|
||||
|
||||
r.GET("/", system.HelloWorld)
|
||||
r.Static("/static", "./static")
|
||||
r.GET("/info", handler.Ping)
|
||||
|
||||
// 监控信息
|
||||
svcd := r.Group("/sd")
|
||||
{
|
||||
svcd.GET("/health", sd.HealthCheck)
|
||||
svcd.GET("/disk", sd.DiskCheck)
|
||||
svcd.GET("/cpu", sd.CPUCheck)
|
||||
svcd.GET("/ram", sd.RAMCheck)
|
||||
svcd.GET("/os", sd.OSCheck)
|
||||
}
|
||||
|
||||
// the jwt middleware
|
||||
authMiddleware, err := middleware.AuthInit()
|
||||
tools.HasError(err, "JWT Init Error", 500)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("JWT Error", err.Error())
|
||||
}
|
||||
// 注册系统路由
|
||||
InitSysRouter(r, authMiddleware)
|
||||
|
||||
r.POST("/login", authMiddleware.LoginHandler)
|
||||
// 注册业务路由
|
||||
// TODO: 这里可存放业务路由,里边并无实际路由是有演示代码
|
||||
InitExamplesRouter(r, authMiddleware)
|
||||
|
||||
// Refresh time can be longer than token timeout
|
||||
r.GET("/refresh_token", authMiddleware.RefreshHandler)
|
||||
r.GET("/routes", Dashboard)
|
||||
|
||||
apiv1 := r.Group("/api/v1")
|
||||
{
|
||||
|
||||
apiv1.GET("/monitor/server", monitor.ServerInfo)
|
||||
|
||||
apiv1.GET("/getCaptcha", system.GenerateCaptchaHandler)
|
||||
apiv1.GET("/db/tables/page", GetDBTableList)
|
||||
apiv1.GET("/db/columns/page", GetDBColumnList)
|
||||
apiv1.GET("/sys/tables/page", GetSysTableList)
|
||||
apiv1.POST("/sys/tables/info", InsertSysTable)
|
||||
apiv1.PUT("/sys/tables/info", UpdateSysTable)
|
||||
apiv1.DELETE("/sys/tables/info/:tableId", DeleteSysTables)
|
||||
apiv1.GET("/sys/tables/info/:tableId", GetSysTables)
|
||||
apiv1.GET("/gen/preview/:tableId", Preview)
|
||||
apiv1.GET("/menuTreeselect", system.GetMenuTreeelect)
|
||||
apiv1.GET("/dict/databytype/:dictType", dict.GetDictDataByDictType)
|
||||
|
||||
}
|
||||
|
||||
auth := r.Group("/api/v1")
|
||||
auth.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
|
||||
auth.GET("/deptList", system.GetDeptList)
|
||||
auth.GET("/deptTree", system.GetDeptTree)
|
||||
auth.GET("/dept/:deptId", system.GetDept)
|
||||
auth.POST("/dept", system.InsertDept)
|
||||
auth.PUT("/dept", system.UpdateDept)
|
||||
auth.DELETE("/dept/:id", system.DeleteDept)
|
||||
|
||||
auth.GET("/dict/datalist", dict.GetDictDataList)
|
||||
auth.GET("/dict/data/:dictCode", dict.GetDictData)
|
||||
auth.POST("/dict/data", dict.InsertDictData)
|
||||
auth.PUT("/dict/data/", dict.UpdateDictData)
|
||||
auth.DELETE("/dict/data/:dictCode", dict.DeleteDictData)
|
||||
|
||||
auth.GET("/dict/typelist", dict.GetDictTypeList)
|
||||
auth.GET("/dict/type/:dictId", dict.GetDictType)
|
||||
auth.POST("/dict/type", dict.InsertDictType)
|
||||
auth.PUT("/dict/type", dict.UpdateDictType)
|
||||
auth.DELETE("/dict/type/:dictId", dict.DeleteDictType)
|
||||
|
||||
auth.GET("/dict/typeoptionselect", dict.GetDictTypeOptionSelect)
|
||||
|
||||
auth.GET("/sysUserList", system.GetSysUserList)
|
||||
auth.GET("/sysUser/:userId", system.GetSysUser)
|
||||
auth.GET("/sysUser/", system.GetSysUserInit)
|
||||
auth.POST("/sysUser", system.InsertSysUser)
|
||||
auth.PUT("/sysUser", system.UpdateSysUser)
|
||||
auth.DELETE("/sysUser/:userId", system.DeleteSysUser)
|
||||
|
||||
auth.GET("/rolelist", system.GetRoleList)
|
||||
auth.GET("/role/:roleId", system.GetRole)
|
||||
auth.POST("/role", system.InsertRole)
|
||||
auth.PUT("/role", system.UpdateRole)
|
||||
auth.PUT("/roledatascope", system.UpdateRoleDataScope)
|
||||
auth.DELETE("/role/:roleId", system.DeleteRole)
|
||||
|
||||
auth.GET("/configList", system.GetConfigList)
|
||||
auth.GET("/config/:configId", system.GetConfig)
|
||||
auth.POST("/config", system.InsertConfig)
|
||||
auth.PUT("/config", system.UpdateConfig)
|
||||
auth.DELETE("/config/:configId", system.DeleteConfig)
|
||||
|
||||
auth.GET("/roleMenuTreeselect/:roleId", system.GetMenuTreeRoleselect)
|
||||
auth.GET("/roleDeptTreeselect/:roleId", system.GetDeptTreeRoleselect)
|
||||
|
||||
auth.GET("/getinfo", system.GetInfo)
|
||||
auth.GET("/user/profile", system.GetSysUserProfile)
|
||||
auth.POST("/user/avatar", system.InsetSysUserAvatar)
|
||||
auth.PUT("/user/pwd", system.SysUserUpdatePwd)
|
||||
|
||||
auth.GET("/postlist", system.GetPostList)
|
||||
auth.GET("/post/:postId", system.GetPost)
|
||||
auth.POST("/post", system.InsertPost)
|
||||
auth.PUT("/post", system.UpdatePost)
|
||||
auth.DELETE("/post/:postId", system.DeletePost)
|
||||
|
||||
auth.GET("/menulist", system.GetMenuList)
|
||||
auth.GET("/menu/:id", system.GetMenu)
|
||||
auth.POST("/menu", system.InsertMenu)
|
||||
auth.PUT("/menu", system.UpdateMenu)
|
||||
auth.DELETE("/menu/:id", system.DeleteMenu)
|
||||
auth.GET("/menurole", system.GetMenuRole)
|
||||
|
||||
auth.GET("/menuids", system.GetMenuIDS)
|
||||
|
||||
auth.GET("/loginloglist", log2.GetLoginLogList)
|
||||
auth.GET("/loginlog/:infoId", log2.GetLoginLog)
|
||||
auth.POST("/loginlog", log2.InsertLoginLog)
|
||||
auth.PUT("/loginlog", log2.UpdateLoginLog)
|
||||
auth.DELETE("/loginlog/:infoId", log2.DeleteLoginLog)
|
||||
|
||||
auth.GET("/operloglist", log2.GetOperLogList)
|
||||
auth.GET("/operlog/:operId", log2.GetOperLog)
|
||||
auth.DELETE("/operlog/:operId", log2.DeleteOperLog)
|
||||
|
||||
auth.GET("/configKey/:configKey", system.GetConfigByConfigKey)
|
||||
|
||||
auth.POST("/logout", handler.LogOut)
|
||||
}
|
||||
//r.NoRoute(authMiddleware.MiddlewareFunc(), NoFound)
|
||||
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
log.Println("路由加载成功!")
|
||||
return r
|
||||
}
|
||||
|
||||
func Dashboard(c *gin.Context) {
|
||||
|
||||
var user = make(map[string]interface{})
|
||||
user["login_name"] = "admin"
|
||||
user["user_id"] = 1
|
||||
user["user_name"] = "管理员"
|
||||
user["dept_id"] = 1
|
||||
|
||||
var cmenuList = make(map[string]interface{})
|
||||
cmenuList["children"] = nil
|
||||
cmenuList["parent_id"] = 1
|
||||
cmenuList["title"] = "用户管理"
|
||||
cmenuList["name"] = "Sysuser"
|
||||
cmenuList["icon"] = "user"
|
||||
cmenuList["order_num"] = 1
|
||||
cmenuList["id"] = 4
|
||||
cmenuList["path"] = "sysuser"
|
||||
cmenuList["component"] = "sysuser/index"
|
||||
|
||||
var lista = make([]interface{}, 1)
|
||||
lista[0] = cmenuList
|
||||
|
||||
var menuList = make(map[string]interface{})
|
||||
menuList["children"] = lista
|
||||
menuList["parent_id"] = 1
|
||||
menuList["name"] = "Upms"
|
||||
menuList["title"] = "权限管理"
|
||||
menuList["icon"] = "example"
|
||||
menuList["order_num"] = 1
|
||||
menuList["id"] = 4
|
||||
menuList["path"] = "/upms"
|
||||
menuList["component"] = "Layout"
|
||||
|
||||
var list = make([]interface{}, 1)
|
||||
list[0] = menuList
|
||||
var data = make(map[string]interface{})
|
||||
data["user"] = user
|
||||
data["menuList"] = list
|
||||
|
||||
var r = make(map[string]interface{})
|
||||
r["code"] = 200
|
||||
r["data"] = data
|
||||
|
||||
c.JSON(200, r)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
log2 "go-admin/apis/log"
|
||||
"go-admin/apis/monitor"
|
||||
"go-admin/apis/system"
|
||||
"go-admin/apis/system/dict"
|
||||
. "go-admin/apis/tools"
|
||||
_ "go-admin/docs"
|
||||
"go-admin/handler"
|
||||
"go-admin/middleware"
|
||||
"go-admin/pkg/jwtauth"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
func InitSysRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.RouterGroup {
|
||||
g := r.Group("")
|
||||
sysBaseRouter(g)
|
||||
// 静态文件
|
||||
sysStaticFileRouter(g)
|
||||
|
||||
// swagger;注意:生产环境可以注释掉
|
||||
sysSwaggerRouter(g)
|
||||
|
||||
// 无需认证
|
||||
sysNoCheckRoleRouter(g)
|
||||
// 需要认证
|
||||
sysCheckRoleRouterInit(g, authMiddleware)
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
func sysBaseRouter(r *gin.RouterGroup) {
|
||||
r.GET("/", system.HelloWorld)
|
||||
r.GET("/info", handler.Ping)
|
||||
}
|
||||
|
||||
func sysStaticFileRouter(r *gin.RouterGroup) {
|
||||
r.Static("/static", "./static")
|
||||
}
|
||||
|
||||
func sysSwaggerRouter(r *gin.RouterGroup) {
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
}
|
||||
|
||||
func sysNoCheckRoleRouter(r *gin.RouterGroup) {
|
||||
v1 := r.Group("/api/v1")
|
||||
|
||||
v1.GET("/monitor/server", monitor.ServerInfo)
|
||||
v1.GET("/getCaptcha", system.GenerateCaptchaHandler)
|
||||
v1.GET("/gen/preview/:tableId", Preview)
|
||||
v1.GET("/menuTreeselect", system.GetMenuTreeelect)
|
||||
v1.GET("/dict/databytype/:dictType", dict.GetDictDataByDictType)
|
||||
|
||||
registerDBRouter(v1)
|
||||
|
||||
registerSysTableRouter(v1)
|
||||
|
||||
}
|
||||
|
||||
func registerDBRouter(api *gin.RouterGroup) {
|
||||
db := api.Group("/db")
|
||||
{
|
||||
db.GET("/tables/page", GetDBTableList)
|
||||
db.GET("/columns/page", GetDBColumnList)
|
||||
}
|
||||
}
|
||||
|
||||
func registerSysTableRouter(v1 *gin.RouterGroup) {
|
||||
systables := v1.Group("/sys/tables")
|
||||
{
|
||||
systables.GET("/page", GetSysTableList)
|
||||
tablesinfo := systables.Group("/info")
|
||||
{
|
||||
tablesinfo.POST("", InsertSysTable)
|
||||
tablesinfo.PUT("", UpdateSysTable)
|
||||
tablesinfo.DELETE("/:tableId", DeleteSysTables)
|
||||
tablesinfo.GET("/:tableId", GetSysTables)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwtauth.GinJWTMiddleware) {
|
||||
r.POST("/login", authMiddleware.LoginHandler)
|
||||
// Refresh time can be longer than token timeout
|
||||
r.GET("/refresh_token", authMiddleware.RefreshHandler)
|
||||
|
||||
v1 := r.Group("/api/v1")
|
||||
|
||||
registerPageRouter(v1, authMiddleware)
|
||||
registerBaseRouter(v1, authMiddleware)
|
||||
registerDeptRouter(v1, authMiddleware)
|
||||
registerDictRouter(v1, authMiddleware)
|
||||
registerSysUserRouter(v1, authMiddleware)
|
||||
registerRoleRouter(v1, authMiddleware)
|
||||
registerConfigRouter(v1, authMiddleware)
|
||||
registerUserCenterRouter(v1, authMiddleware)
|
||||
registerPostRouter(v1, authMiddleware)
|
||||
registerMenuRouter(v1, authMiddleware)
|
||||
registerLoginLogRouter(v1, authMiddleware)
|
||||
registerOperLogRouter(v1, authMiddleware)
|
||||
}
|
||||
|
||||
func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
v1auth := v1.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
v1auth.GET("/getinfo", system.GetInfo)
|
||||
v1auth.GET("/menurole", system.GetMenuRole)
|
||||
v1auth.PUT("/roledatascope", system.UpdateRoleDataScope)
|
||||
v1auth.GET("/roleMenuTreeselect/:roleId", system.GetMenuTreeRoleselect)
|
||||
v1auth.GET("/roleDeptTreeselect/:roleId", system.GetDeptTreeRoleselect)
|
||||
|
||||
v1auth.POST("/logout", handler.LogOut)
|
||||
v1auth.GET("/menuids", system.GetMenuIDS)
|
||||
|
||||
v1auth.GET("/operloglist", log2.GetOperLogList)
|
||||
v1auth.GET("/configKey/:configKey", system.GetConfigByConfigKey)
|
||||
}
|
||||
}
|
||||
|
||||
func registerPageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
v1auth := v1.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
v1auth.GET("/deptList", system.GetDeptList)
|
||||
v1auth.GET("/deptTree", system.GetDeptTree)
|
||||
v1auth.GET("/sysUserList", system.GetSysUserList)
|
||||
v1auth.GET("/rolelist", system.GetRoleList)
|
||||
v1auth.GET("/configList", system.GetConfigList)
|
||||
v1auth.GET("/postlist", system.GetPostList)
|
||||
v1auth.GET("/menulist", system.GetMenuList)
|
||||
v1auth.GET("/loginloglist", log2.GetLoginLogList)
|
||||
}
|
||||
}
|
||||
|
||||
func registerUserCenterRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
user := v1.Group("/user").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
user.GET("/profile", system.GetSysUserProfile)
|
||||
user.POST("/avatar", system.InsetSysUserAvatar)
|
||||
user.PUT("/pwd", system.SysUserUpdatePwd)
|
||||
}
|
||||
}
|
||||
|
||||
func registerOperLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
operlog := v1.Group("/operlog").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
operlog.GET("/:operId", log2.GetOperLog)
|
||||
operlog.DELETE("/:operId", log2.DeleteOperLog)
|
||||
}
|
||||
}
|
||||
|
||||
func registerLoginLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
loginlog := v1.Group("/loginlog").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
loginlog.GET("/:infoId", log2.GetLoginLog)
|
||||
loginlog.POST("", log2.InsertLoginLog)
|
||||
loginlog.PUT("", log2.UpdateLoginLog)
|
||||
loginlog.DELETE("/:infoId", log2.DeleteLoginLog)
|
||||
}
|
||||
}
|
||||
|
||||
func registerPostRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
post := v1.Group("/post").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
post.GET("/:postId", system.GetPost)
|
||||
post.POST("", system.InsertPost)
|
||||
post.PUT("", system.UpdatePost)
|
||||
post.DELETE("/:postId", system.DeletePost)
|
||||
}
|
||||
}
|
||||
|
||||
func registerMenuRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
menu := v1.Group("/menu").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
menu.GET("/:id", system.GetMenu)
|
||||
menu.POST("", system.InsertMenu)
|
||||
menu.PUT("", system.UpdateMenu)
|
||||
menu.DELETE("/:id", system.DeleteMenu)
|
||||
}
|
||||
}
|
||||
|
||||
func registerConfigRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
config := v1.Group("/config").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
config.GET("/:configId", system.GetConfig)
|
||||
config.POST("", system.InsertConfig)
|
||||
config.PUT("", system.UpdateConfig)
|
||||
config.DELETE("/:configId", system.DeleteConfig)
|
||||
}
|
||||
}
|
||||
|
||||
func registerRoleRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
role := v1.Group("/role").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
role.GET("/:roleId", system.GetRole)
|
||||
role.POST("", system.InsertRole)
|
||||
role.PUT("", system.UpdateRole)
|
||||
role.DELETE("/:roleId", system.DeleteRole)
|
||||
}
|
||||
}
|
||||
|
||||
func registerSysUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
sysuser := v1.Group("/sysUser").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
sysuser.GET("/:userId", system.GetSysUser)
|
||||
sysuser.GET("/", system.GetSysUserInit)
|
||||
sysuser.POST("", system.InsertSysUser)
|
||||
sysuser.PUT("", system.UpdateSysUser)
|
||||
sysuser.DELETE("/:userId", system.DeleteSysUser)
|
||||
}
|
||||
}
|
||||
|
||||
func registerDictRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
dicts := v1.Group("/dict").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
dicts.GET("/datalist", dict.GetDictDataList)
|
||||
dicts.GET("/typelist", dict.GetDictTypeList)
|
||||
dicts.GET("/typeoptionselect", dict.GetDictTypeOptionSelect)
|
||||
|
||||
dicts.GET("/data/:dictCode", dict.GetDictData)
|
||||
dicts.POST("/data", dict.InsertDictData)
|
||||
dicts.PUT("/data/", dict.UpdateDictData)
|
||||
dicts.DELETE("/data/:dictCode", dict.DeleteDictData)
|
||||
|
||||
dicts.GET("/type/:dictId", dict.GetDictType)
|
||||
dicts.POST("/type", dict.InsertDictType)
|
||||
dicts.PUT("/type", dict.UpdateDictType)
|
||||
dicts.DELETE("/type/:dictId", dict.DeleteDictType)
|
||||
}
|
||||
}
|
||||
|
||||
func registerDeptRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
dept := v1.Group("/dept").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
dept.GET("/:deptId", system.GetDept)
|
||||
dept.POST("", system.InsertDept)
|
||||
dept.PUT("", system.UpdateDept)
|
||||
dept.DELETE("/:id", system.DeleteDept)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ var (
|
||||
CreatedSuccess = "创建成功!"
|
||||
UpdatedSuccess = "更新成功!"
|
||||
DeletedSuccess = "删除成功!"
|
||||
DeletedFail = "删除失败!"
|
||||
GetSuccess = "查询成功!"
|
||||
NotFound = "未找到相关内容或者数据为空!"
|
||||
)
|
||||
|
||||
@@ -14,9 +14,6 @@ var cfgApplication *viper.Viper
|
||||
var cfgJwt *viper.Viper
|
||||
var cfgLog *viper.Viper
|
||||
|
||||
//func init() {
|
||||
// InitConfig("settings.dev")
|
||||
//}
|
||||
|
||||
//载入配置文件
|
||||
func ConfigSetup(path string) {
|
||||
@@ -58,9 +55,6 @@ func ConfigSetup(path string) {
|
||||
LogConfig = InitLog(cfgLog)
|
||||
}
|
||||
|
||||
func SetApplicationIsInit() {
|
||||
SetConfig("./config", "settings.application.isInit", false)
|
||||
}
|
||||
|
||||
func SetConfig(configPath string, key string, value interface{}) {
|
||||
viper.AddConfigPath(configPath)
|
||||
|
||||
@@ -53,3 +53,16 @@ func JsonStrToMap(e string) (map[string]interface{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func StructToMap(data interface{}) (map[string]interface{}, error) {
|
||||
dataBytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mapData := make(map[string]interface{})
|
||||
err = json.Unmarshal(dataBytes, &mapData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapData, nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,6 @@ func StrToInt(err error, index string) int {
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
func CompareHashAndPassword(e string, p string) (bool, error) {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(e), []byte(p))
|
||||
if err != nil {
|
||||
@@ -50,6 +49,7 @@ func HasError(err error, msg string, code ...int) {
|
||||
if msg == "" {
|
||||
msg = err.Error()
|
||||
}
|
||||
log.Println(err)
|
||||
panic("CustomError#" + strconv.Itoa(statusCode) + "#" + msg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user