mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【优化】租户功能,框架优化
This commit is contained in:
@@ -11,9 +11,8 @@ import (
|
||||
sysEntity "pandax/apps/system/entity"
|
||||
sysServices "pandax/apps/system/services"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -413,9 +412,9 @@ func GenCode(tableId int64) {
|
||||
kgo.KFile.Mkdir("./apps/"+tab.PackageName+"/entity/", os.ModePerm)
|
||||
kgo.KFile.Mkdir("./apps/"+tab.PackageName+"/router/", os.ModePerm)
|
||||
kgo.KFile.Mkdir("./apps/"+tab.PackageName+"/services/", os.ModePerm)
|
||||
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/", os.ModePerm)
|
||||
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/", os.ModePerm)
|
||||
kgo.KFile.Mkdir(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/"+"component"+"/", os.ModePerm)
|
||||
kgo.KFile.Mkdir(global.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/", os.ModePerm)
|
||||
kgo.KFile.Mkdir(global.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/", os.ModePerm)
|
||||
kgo.KFile.Mkdir(global.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/"+"component"+"/", os.ModePerm)
|
||||
|
||||
var b1 bytes.Buffer
|
||||
err = t1.Execute(&b1, tab)
|
||||
@@ -436,9 +435,9 @@ func GenCode(tableId int64) {
|
||||
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/services/"+tab.TableName+".go", b2.Bytes())
|
||||
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/api/"+tab.TableName+".go", b3.Bytes())
|
||||
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/router/"+tab.TableName+".go", b4.Bytes())
|
||||
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/"+tab.BusinessName+".js", b5.Bytes())
|
||||
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/index.vue", b6.Bytes())
|
||||
kgo.KFile.WriteFile(config.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/"+"component"+"/editModule.vue", b7.Bytes())
|
||||
kgo.KFile.WriteFile(global.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/"+tab.BusinessName+".js", b5.Bytes())
|
||||
kgo.KFile.WriteFile(global.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/index.vue", b6.Bytes())
|
||||
kgo.KFile.WriteFile(global.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/"+"component"+"/editModule.vue", b7.Bytes())
|
||||
}
|
||||
|
||||
// GenConfigure 生成菜单,api
|
||||
|
||||
@@ -4,9 +4,8 @@ import (
|
||||
"errors"
|
||||
"pandax/apps/develop/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -43,22 +42,22 @@ func (m *devGenTableModelImpl) FindDbTablesListPage(page, pageSize int, data ent
|
||||
pgdata := make([]map[string]any, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
if config.Conf.Server.DbType != "mysql" && config.Conf.Server.DbType != "postgresql" {
|
||||
if global.Conf.Server.DbType != "mysql" && global.Conf.Server.DbType != "postgresql" {
|
||||
biz.ErrIsNil(errors.New("只支持mysql和postgresql数据库"), "只支持mysql和postgresql数据库")
|
||||
}
|
||||
|
||||
db := global.Db.Table("information_schema.tables")
|
||||
if config.Conf.Server.DbType == "mysql" {
|
||||
db = db.Where("table_schema= ? ", config.Conf.Gen.Dbname)
|
||||
if global.Conf.Server.DbType == "mysql" {
|
||||
db = db.Where("table_schema= ? ", global.Conf.Gen.Dbname)
|
||||
}
|
||||
if config.Conf.Server.DbType == "postgresql" {
|
||||
if global.Conf.Server.DbType == "postgresql" {
|
||||
db = db.Where("table_schema = ? ", "public")
|
||||
}
|
||||
db = db.Where("table_name NOT LIKE 'dev_%'")
|
||||
if data.TableName != "" {
|
||||
db = db.Where("table_name like ?", "%"+data.TableName+"%")
|
||||
}
|
||||
if config.Conf.Server.DbType == "mysql" {
|
||||
if global.Conf.Server.DbType == "mysql" {
|
||||
err := db.Limit(pageSize).Offset(offset).Find(&list).Offset(-1).Limit(-1).Count(&total).Error
|
||||
biz.ErrIsNil(err, "查询配置分页列表信息失败")
|
||||
return &list, total
|
||||
@@ -74,14 +73,14 @@ func (m *devGenTableModelImpl) FindDbTablesListPage(page, pageSize int, data ent
|
||||
|
||||
func (m *devGenTableModelImpl) FindDbTableOne(tableName string) *entity.DBTables {
|
||||
resData := new(entity.DBTables)
|
||||
if config.Conf.Server.DbType != "mysql" && config.Conf.Server.DbType != "postgresql" {
|
||||
if global.Conf.Server.DbType != "mysql" && global.Conf.Server.DbType != "postgresql" {
|
||||
biz.ErrIsNil(errors.New("只支持mysql和postgresql数据库"), "只支持mysql和postgresql数据库")
|
||||
}
|
||||
db := global.Db.Table("information_schema.tables")
|
||||
if config.Conf.Server.DbType != "mysql" {
|
||||
db = db.Where("table_schema= ? ", config.Conf.Gen.Dbname)
|
||||
if global.Conf.Server.DbType != "mysql" {
|
||||
db = db.Where("table_schema= ? ", global.Conf.Gen.Dbname)
|
||||
}
|
||||
if config.Conf.Server.DbType != "postgresql" {
|
||||
if global.Conf.Server.DbType != "postgresql" {
|
||||
db = db.Where("table_schema= ? ", "public")
|
||||
}
|
||||
db = db.Where("table_name = ?", tableName)
|
||||
|
||||
@@ -4,8 +4,7 @@ import (
|
||||
"errors"
|
||||
"pandax/apps/develop/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -38,14 +37,14 @@ func (m *devTableColumnModelImpl) FindDbTablesColumnListPage(page, pageSize int,
|
||||
list := make([]entity.DBColumns, 0)
|
||||
var total int64 = 0
|
||||
offset := pageSize * (page - 1)
|
||||
if config.Conf.Server.DbType != "mysql" && config.Conf.Server.DbType != "postgresql" {
|
||||
if global.Conf.Server.DbType != "mysql" && global.Conf.Server.DbType != "postgresql" {
|
||||
biz.ErrIsNil(errors.New("只支持mysql和postgresql数据库"), "只支持mysql和postgresql数据库")
|
||||
}
|
||||
db := global.Db.Table("information_schema.COLUMNS")
|
||||
if config.Conf.Server.DbType == "mysql" {
|
||||
db = db.Where("table_schema= ? ", config.Conf.Gen.Dbname)
|
||||
if global.Conf.Server.DbType == "mysql" {
|
||||
db = db.Where("table_schema= ? ", global.Conf.Gen.Dbname)
|
||||
}
|
||||
if config.Conf.Server.DbType == "postgresql" {
|
||||
if global.Conf.Server.DbType == "postgresql" {
|
||||
db = db.Where("table_schema = ? ", "public")
|
||||
}
|
||||
|
||||
@@ -61,14 +60,14 @@ func (m *devTableColumnModelImpl) FindDbTablesColumnListPage(page, pageSize int,
|
||||
|
||||
func (m *devTableColumnModelImpl) FindDbTableColumnList(tableName string) *[]entity.DBColumns {
|
||||
resData := make([]entity.DBColumns, 0)
|
||||
if config.Conf.Server.DbType != "mysql" && config.Conf.Server.DbType != "postgresql" {
|
||||
if global.Conf.Server.DbType != "mysql" && global.Conf.Server.DbType != "postgresql" {
|
||||
biz.ErrIsNil(errors.New("只支持mysql和postgresql数据库"), "只支持mysql和postgresql数据库")
|
||||
}
|
||||
db := global.Db.Table("information_schema.columns")
|
||||
if config.Conf.Server.DbType == "mysql" {
|
||||
db = db.Where("table_schema= ? ", config.Conf.Gen.Dbname)
|
||||
if global.Conf.Server.DbType == "mysql" {
|
||||
db = db.Where("table_schema= ? ", global.Conf.Gen.Dbname)
|
||||
}
|
||||
if config.Conf.Server.DbType == "postgresql" {
|
||||
if global.Conf.Server.DbType == "postgresql" {
|
||||
db = db.Where("table_schema = ? ", "public")
|
||||
}
|
||||
biz.IsTrue(tableName != "", "table name cannot be empty!")
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
logEntity "pandax/apps/log/entity"
|
||||
logServices "pandax/apps/log/services"
|
||||
|
||||
"pandax/base/global"
|
||||
"pandax/base/httpclient"
|
||||
"pandax/pkg/global"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/job/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/log/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/resource/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/resource/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type SystemApiApi struct {
|
||||
@@ -120,5 +121,6 @@ func (s *SystemApiApi) GetAllApis(rc *ctx.ReqCtx) {
|
||||
// @Router /casbin/getPolicyPathByRoleId [get]
|
||||
func (s *SystemApiApi) GetPolicyPathByRoleId(rc *ctx.ReqCtx) {
|
||||
roleKey := rc.GinCtx.Query("roleKey")
|
||||
rc.ResData = casbin.GetPolicyPathByRoleId(roleKey)
|
||||
tenantId := strconv.Itoa(int(rc.LoginAccount.TenantId))
|
||||
rc.ResData = casbin.GetPolicyPathByRoleId(tenantId, roleKey)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"pandax/base/biz"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type DeptApi struct {
|
||||
|
||||
@@ -5,11 +5,10 @@ import (
|
||||
entity "pandax/apps/system/entity"
|
||||
services "pandax/apps/system/services"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/config"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type DictApi struct {
|
||||
@@ -132,7 +131,7 @@ func (p *DictApi) ExportDictType(rc *ctx.ReqCtx) {
|
||||
dictType := rc.GinCtx.Query("dictType")
|
||||
|
||||
list := p.DictType.FindList(entity.SysDictType{Status: status, DictName: dictName, DictType: dictType})
|
||||
fileName := utils.GetFileName(config.Conf.Server.ExcelDir, filename)
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
rc.Download(fileName)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"pandax/base/biz"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type PostApi struct {
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
services "pandax/apps/system/services"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/casbin"
|
||||
"pandax/base/config"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RoleApi struct {
|
||||
@@ -79,11 +79,13 @@ func (r *RoleApi) InsertRole(rc *ctx.ReqCtx) {
|
||||
var role entity.SysRole
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &role)
|
||||
role.CreateBy = rc.LoginAccount.UserName
|
||||
role.TenantId = rc.LoginAccount.TenantId
|
||||
insert := r.RoleApp.Insert(role)
|
||||
role.RoleId = insert.RoleId
|
||||
r.RoleMenuApp.Insert(insert.RoleId, role.MenuIds)
|
||||
//添加权限
|
||||
casbin.UpdateCasbin(role.RoleKey, role.ApiIds)
|
||||
tenantId := strconv.Itoa(int(rc.LoginAccount.TenantId))
|
||||
casbin.UpdateCasbin(tenantId, role.RoleKey, role.ApiIds)
|
||||
}
|
||||
|
||||
// @Summary 修改用户角色
|
||||
@@ -106,7 +108,8 @@ func (r *RoleApi) UpdateRole(rc *ctx.ReqCtx) {
|
||||
// 添加角色菜单绑定
|
||||
r.RoleMenuApp.Insert(role.RoleId, role.MenuIds)
|
||||
//修改api权限
|
||||
casbin.UpdateCasbin(role.RoleKey, role.ApiIds)
|
||||
tenantId := strconv.Itoa(int(rc.LoginAccount.TenantId))
|
||||
casbin.UpdateCasbin(tenantId, role.RoleKey, role.ApiIds)
|
||||
}
|
||||
|
||||
// @Summary 修改用户角色状态
|
||||
@@ -198,7 +201,7 @@ func (p *RoleApi) ExportRole(rc *ctx.ReqCtx) {
|
||||
roleKey := rc.GinCtx.Query("roleKey")
|
||||
|
||||
list := p.RoleApp.FindList(entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey})
|
||||
fileName := utils.GetFileName(config.Conf.Server.ExcelDir, filename)
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
rc.Download(fileName)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type SysTenantsApi struct {
|
||||
// @Param pageSize query int false "页条数"
|
||||
// @Param pageNum query int false "页码"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /admin/tenant/list [get]
|
||||
// @Router /system/tenant/list [get]
|
||||
// @Security
|
||||
func (p *SysTenantsApi) GetSysTenantsList(rc *ctx.ReqCtx) {
|
||||
data := entity.SysTenants{}
|
||||
@@ -39,12 +39,28 @@ func (p *SysTenantsApi) GetSysTenantsList(rc *ctx.ReqCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary SysTenants列表数据
|
||||
// @Tags SysTenants
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /system/tenant/lists [get]
|
||||
// @Security
|
||||
func (p *SysTenantsApi) GetSysTenantsAll(rc *ctx.ReqCtx) {
|
||||
list := make([]entity.SysTenants, 0)
|
||||
if rc.LoginAccount.RoleKey == "admin" {
|
||||
data := entity.SysTenants{}
|
||||
list = *p.SysTenantsApp.FindList(data)
|
||||
} else {
|
||||
list = append(list, *p.SysTenantsApp.FindOne(rc.LoginAccount.TenantId))
|
||||
}
|
||||
rc.ResData = list
|
||||
}
|
||||
|
||||
// @Summary 获取SysTenants
|
||||
// @Description 获取JSON
|
||||
// @Tags SysTenants
|
||||
// @Param tenantId path int true "tenantId"
|
||||
// @Success 200 {string} string "{"code": 200, "data": [...]}"
|
||||
// @Router /admin/tenant/{tenantId} [get]
|
||||
// @Router /system/tenant/{tenantId} [get]
|
||||
// @Security
|
||||
func (p *SysTenantsApi) GetSysTenants(rc *ctx.ReqCtx) {
|
||||
tenantId := ginx.PathParamInt(rc.GinCtx, "tenantId")
|
||||
@@ -59,7 +75,7 @@ func (p *SysTenantsApi) GetSysTenants(rc *ctx.ReqCtx) {
|
||||
// @Param data body entity.SysTenants true "data"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /admin/tenant [post]
|
||||
// @Router /system/tenant [post]
|
||||
// @Security X-TOKEN
|
||||
func (p *SysTenantsApi) InsertSysTenants(rc *ctx.ReqCtx) {
|
||||
var data entity.SysTenants
|
||||
@@ -76,7 +92,7 @@ func (p *SysTenantsApi) InsertSysTenants(rc *ctx.ReqCtx) {
|
||||
// @Param data body entity.SysTenants true "body"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "添加失败"}"
|
||||
// @Router /admin/tenant [put]
|
||||
// @Router /system/tenant [put]
|
||||
// @Security X-TOKEN
|
||||
func (p *SysTenantsApi) UpdateSysTenants(rc *ctx.ReqCtx) {
|
||||
var data entity.SysTenants
|
||||
@@ -91,7 +107,7 @@ func (p *SysTenantsApi) UpdateSysTenants(rc *ctx.ReqCtx) {
|
||||
// @Param tenantId path string true "tenantId"
|
||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
||||
// @Success 200 {string} string "{"code": 400, "message": "删除失败"}"
|
||||
// @Router /admin/tenant/{tenantId} [delete]
|
||||
// @Router /system/tenant/{tenantId} [delete]
|
||||
func (p *SysTenantsApi) DeleteSysTenants(rc *ctx.ReqCtx) {
|
||||
tenantId := rc.GinCtx.Param("tenantId")
|
||||
tenantIds := utils.IdsStrToIdsIntGroup(tenantId)
|
||||
|
||||
@@ -16,11 +16,10 @@ import (
|
||||
"pandax/apps/system/services"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/captcha"
|
||||
"pandax/base/config"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/ginx"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -52,9 +51,10 @@ func (u *UserApi) GenerateCaptcha(c *gin.Context) {
|
||||
// @Router /system/user/refreshToken [get]
|
||||
func (u *UserApi) RefreshToken(rc *ctx.ReqCtx) {
|
||||
tokenStr := rc.GinCtx.Request.Header.Get("X-TOKEN")
|
||||
token, err := ctx.RefreshToken(tokenStr)
|
||||
j := ctx.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256)
|
||||
token, err := j.RefreshToken(tokenStr)
|
||||
biz.ErrIsNil(err, "刷新token失败")
|
||||
rc.ResData = map[string]any{"token": token, "expire": time.Now().Unix() + config.Conf.Jwt.ExpireTime}
|
||||
rc.ResData = map[string]any{"token": token, "expire": time.Now().Unix() + global.Conf.Jwt.ExpireTime}
|
||||
}
|
||||
|
||||
// @Tags Base
|
||||
@@ -70,27 +70,26 @@ func (u *UserApi) Login(rc *ctx.ReqCtx) {
|
||||
|
||||
login := u.UserApp.Login(entity.Login{Username: l.Username, Password: l.Password})
|
||||
role := u.RoleApp.FindOne(login.RoleId)
|
||||
|
||||
token, err := ctx.CreateToken(
|
||||
ctx.Claims{
|
||||
UserId: login.UserId,
|
||||
UserName: login.Username,
|
||||
RoleId: login.RoleId,
|
||||
RoleKey: role.RoleKey,
|
||||
DeptId: login.DeptId,
|
||||
PostId: login.PostId,
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
|
||||
ExpiresAt: time.Now().Unix() + config.Conf.Jwt.ExpireTime, // 过期时间 7天 配置文件
|
||||
Issuer: "PandaX", // 签名的发行者
|
||||
},
|
||||
})
|
||||
|
||||
j := ctx.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256)
|
||||
token, err := j.CreateToken(ctx.Claims{
|
||||
UserId: login.UserId,
|
||||
TenantId: login.TenantId,
|
||||
UserName: login.Username,
|
||||
RoleId: login.RoleId,
|
||||
RoleKey: role.RoleKey,
|
||||
DeptId: login.DeptId,
|
||||
PostId: login.PostId,
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
|
||||
ExpiresAt: time.Now().Unix() + global.Conf.Jwt.ExpireTime, // 过期时间 7天 配置文件
|
||||
Issuer: "PandaX", // 签名的发行者
|
||||
},
|
||||
})
|
||||
biz.ErrIsNil(err, "生成Token失败")
|
||||
|
||||
rc.ResData = map[string]any{
|
||||
"token": token,
|
||||
"expire": time.Now().Unix() + config.Conf.Jwt.ExpireTime,
|
||||
"expire": time.Now().Unix() + global.Conf.Jwt.ExpireTime,
|
||||
}
|
||||
|
||||
var loginLog logEntity.LogLogin
|
||||
@@ -420,7 +419,7 @@ func (u *UserApi) ExportUser(rc *ctx.ReqCtx) {
|
||||
user.Username = userName
|
||||
user.Phone = phone
|
||||
list := u.UserApp.FindList(user)
|
||||
fileName := utils.GetFileName(config.Conf.Server.ExcelDir, filename)
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
rc.Download(fileName)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
type SysRole struct {
|
||||
model.BaseModel
|
||||
RoleId int64 `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"`
|
||||
TenantId int64 `json:"tenantId" gorm:"type:int"`
|
||||
RoleName string `json:"roleName" gorm:"type:varchar(128);comment:角色名称"`
|
||||
Status string `json:"status" gorm:"type:varchar(1);comment:状态"`
|
||||
RoleKey string `json:"roleKey" gorm:"type:varchar(128);comment:角色代码"`
|
||||
|
||||
@@ -12,21 +12,23 @@ type SysUserId struct {
|
||||
}
|
||||
|
||||
type SysUserB struct {
|
||||
NickName string `gorm:"type:varchar(128)" json:"nickName"` // 昵称
|
||||
Phone string `gorm:"type:varchar(11)" json:"phone"` // 手机号
|
||||
RoleId int64 `gorm:"type:int" json:"roleId"` // 角色编码
|
||||
Salt string `gorm:"type:varchar(255)" json:"salt"` //盐
|
||||
Avatar string `gorm:"type:varchar(255)" json:"avatar"` //头像
|
||||
Sex string `gorm:"type:varchar(255)" json:"sex"` //性别
|
||||
Email string `gorm:"type:varchar(128)" json:"email"` //邮箱
|
||||
DeptId int64 `gorm:"type:int" json:"deptId"` //部门编码
|
||||
PostId int64 `gorm:"type:int" json:"postId"` //职位编码
|
||||
RoleIds string `gorm:"type:varchar(255)" json:"roleIds"` //多角色
|
||||
PostIds string `gorm:"type:varchar(255)" json:"postIds"` // 多岗位
|
||||
CreateBy string `gorm:"type:varchar(128)" json:"createBy"` //
|
||||
UpdateBy string `gorm:"type:varchar(128)" json:"updateBy"` //
|
||||
Remark string `gorm:"type:varchar(255)" json:"remark"` //备注
|
||||
Status string `gorm:"type:varchar(1);" json:"status"`
|
||||
TenantId int64 `gorm:"type:int" json:"tenantId"` //租户id
|
||||
NickName string `gorm:"type:varchar(128)" json:"nickName"` // 昵称
|
||||
Phone string `gorm:"type:varchar(11)" json:"phone"` // 手机号
|
||||
RoleId int64 `gorm:"type:int" json:"roleId"` // 角色编码
|
||||
Salt string `gorm:"type:varchar(255)" json:"salt"` //盐
|
||||
Avatar string `gorm:"type:varchar(255)" json:"avatar"` //头像
|
||||
Sex string `gorm:"type:varchar(255)" json:"sex"` //性别
|
||||
Email string `gorm:"type:varchar(128)" json:"email"` //邮箱
|
||||
DeptId int64 `gorm:"type:int" json:"deptId"` //部门编码
|
||||
PostId int64 `gorm:"type:int" json:"postId"` //职位编码
|
||||
RoleIds string `gorm:"type:varchar(255)" json:"roleIds"` //多角色
|
||||
PostIds string `gorm:"type:varchar(255)" json:"postIds"` // 多岗位
|
||||
CreateBy string `gorm:"type:varchar(128)" json:"createBy"` //
|
||||
UpdateBy string `gorm:"type:varchar(128)" json:"updateBy"` //
|
||||
Remark string `gorm:"type:varchar(255)" json:"remark"` //备注
|
||||
Status string `gorm:"type:varchar(1);" json:"status"`
|
||||
SysTenants SysTenants `gorm:"foreignKey:TenantId;references:Id" json:"tenants"`
|
||||
model.BaseModel
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,10 @@ func InitSysTenantRouter(router *gin.RouterGroup) {
|
||||
routerGroup.GET("list", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(SysTenantListLog).Handle(s.GetSysTenantsList)
|
||||
})
|
||||
|
||||
SysTenantAllLog := ctx.NewLogInfo("获取SysTenant列表")
|
||||
routerGroup.GET("lists", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(SysTenantAllLog).Handle(s.GetSysTenantsAll)
|
||||
})
|
||||
SysTenantLog := ctx.NewLogInfo("获取SysTenant信息")
|
||||
routerGroup.GET(":tenantId", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithLog(SysTenantLog).Handle(s.GetSysTenants)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/casbin"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/kakuilan/kgo"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -8,7 +8,7 @@ package services
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -38,7 +38,7 @@ func (m *SysTenantModelImpl) Insert(data entity.SysTenants) *entity.SysTenants {
|
||||
|
||||
func (m *SysTenantModelImpl) FindOne(tenantId int64) *entity.SysTenants {
|
||||
resData := new(entity.SysTenants)
|
||||
err := global.Db.Table(m.table).Where("tenant_id = ?", tenantId).First(resData).Error
|
||||
err := global.Db.Table(m.table).Where("id = ?", tenantId).First(resData).Error
|
||||
biz.ErrIsNil(err, "查询SysTenant失败")
|
||||
return resData
|
||||
}
|
||||
@@ -81,5 +81,5 @@ func (m *SysTenantModelImpl) Update(data entity.SysTenants) *entity.SysTenants {
|
||||
}
|
||||
|
||||
func (m *SysTenantModelImpl) Delete(tenantIds []int64) {
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Delete(&entity.SysTenants{}, "tenant_id in (?)", tenantIds).Error, "删除SysTenant失败")
|
||||
biz.ErrIsNil(global.Db.Table(m.table).Delete(&entity.SysTenants{}, "id in (?)", tenantIds).Error, "删除SysTenant失败")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -31,12 +32,19 @@ var SysUserModelDao SysUserModel = &sysUserModelImpl{
|
||||
|
||||
func (m *sysUserModelImpl) Login(u entity.Login) *entity.SysUser {
|
||||
user := new(entity.SysUser)
|
||||
|
||||
err := global.Db.Table(m.table).Where("username = ? ", u.Username).Find(user)
|
||||
biz.ErrIsNil(err.Error, "查询用户信息失败")
|
||||
|
||||
// 验证密码
|
||||
b := kgo.KEncr.PasswordVerify([]byte(u.Password), []byte(user.Password))
|
||||
biz.IsTrue(b, "密码错误")
|
||||
|
||||
//验证租户
|
||||
if SysTenantModelDao.FindOne(user.TenantId).ExpireTime.Unix() < time.Now().Unix() {
|
||||
biz.IsTrue(b, "租户已经过期")
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
@@ -61,27 +69,25 @@ func (m *sysUserModelImpl) FindOne(data entity.SysUser) *entity.SysUserView {
|
||||
if data.UserId != 0 {
|
||||
db = db.Where("user_id = ?", data.UserId)
|
||||
}
|
||||
|
||||
if data.TenantId != 0 {
|
||||
db = db.Where("tenant_id = ?", data.TenantId)
|
||||
}
|
||||
if data.Username != "" {
|
||||
db = db.Where("username = ?", data.Username)
|
||||
}
|
||||
|
||||
if data.Password != "" {
|
||||
db = db.Where("password = ?", data.Password)
|
||||
}
|
||||
|
||||
if data.RoleId != 0 {
|
||||
db = db.Where("role_id = ?", data.RoleId)
|
||||
}
|
||||
|
||||
if data.DeptId != 0 {
|
||||
db = db.Where("dept_id = ?", data.DeptId)
|
||||
}
|
||||
|
||||
if data.PostId != 0 {
|
||||
db = db.Where("post_id = ?", data.PostId)
|
||||
}
|
||||
biz.ErrIsNil(db.First(resData).Error, "查询用户失败")
|
||||
biz.ErrIsNil(db.Preload("SysTenants").First(resData).Error, "查询用户失败")
|
||||
|
||||
return resData
|
||||
}
|
||||
@@ -96,7 +102,9 @@ func (m *sysUserModelImpl) FindListPage(page, pageSize int, data entity.SysUser)
|
||||
if data.Username != "" {
|
||||
db = db.Where("sys_users.username = ?", data.Username)
|
||||
}
|
||||
|
||||
if data.TenantId != 0 {
|
||||
db = db.Where("sys_users.tenant_id = ?", data.TenantId)
|
||||
}
|
||||
if data.NickName != "" {
|
||||
db = db.Where("sys_users.nick_name like ?", "%"+data.NickName+"%")
|
||||
}
|
||||
@@ -113,7 +121,7 @@ func (m *sysUserModelImpl) FindListPage(page, pageSize int, data entity.SysUser)
|
||||
}
|
||||
db.Where("sys_users.delete_time IS NULL")
|
||||
err := db.Count(&total).Error
|
||||
err = db.Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
err = db.Limit(pageSize).Offset(offset).Preload("SysTenants").Find(&list).Error
|
||||
biz.ErrIsNil(err, "查询用户分页列表失败")
|
||||
return &list, total
|
||||
}
|
||||
@@ -126,7 +134,9 @@ func (m *sysUserModelImpl) FindList(data entity.SysUser) *[]entity.SysUserView {
|
||||
if data.UserId != 0 {
|
||||
db = db.Where("user_id = ?", data.UserId)
|
||||
}
|
||||
|
||||
if data.TenantId != 0 {
|
||||
db = db.Where("tenant_id = ?", data.TenantId)
|
||||
}
|
||||
if data.Username != "" {
|
||||
db = db.Where("username = ?", data.Username)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package biz
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pandax/base/global"
|
||||
"pandax/base/utils"
|
||||
"reflect"
|
||||
)
|
||||
@@ -12,7 +11,6 @@ func ErrIsNil(err error, msg string, params ...any) {
|
||||
if err.Error() == "record not found" {
|
||||
return
|
||||
}
|
||||
global.Log.Error(msg + ": " + err.Error())
|
||||
panic(any(NewBizErr(fmt.Sprintf(msg, params...))))
|
||||
}
|
||||
}
|
||||
@@ -28,7 +26,6 @@ func IsNil(err error) {
|
||||
case *BizError:
|
||||
panic(any(t))
|
||||
case error:
|
||||
global.Log.Error("非业务异常: " + err.Error())
|
||||
panic(any(NewBizErr(fmt.Sprintf("非业务异常: %s", err.Error()))))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,15 @@ import (
|
||||
"github.com/casbin/casbin/v2"
|
||||
gormadapter "github.com/casbin/gorm-adapter/v3"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func UpdateCasbin(roleKey string, casbinInfos []CasbinRule) error {
|
||||
ClearCasbin(0, roleKey)
|
||||
func UpdateCasbin(tenantId string, roleKey string, casbinInfos []CasbinRule) error {
|
||||
ClearCasbin(0, tenantId, roleKey)
|
||||
rules := [][]string{}
|
||||
for _, v := range casbinInfos {
|
||||
rules = append(rules, []string{roleKey, v.Path, v.Method})
|
||||
rules = append(rules, []string{tenantId, roleKey, v.Path, v.Method})
|
||||
}
|
||||
e := Casbin()
|
||||
success, _ := e.AddPolicies(rules)
|
||||
@@ -22,20 +21,20 @@ func UpdateCasbin(roleKey string, casbinInfos []CasbinRule) error {
|
||||
}
|
||||
|
||||
func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) {
|
||||
err := global.Db.Table("casbin_rule").Model(&CasbinRule{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]any{
|
||||
"v1": newPath,
|
||||
"v2": newMethod,
|
||||
err := global.Db.Table("casbin_rule").Model(&CasbinRule{}).Where("v2 = ? AND v3 = ?", oldPath, oldMethod).Updates(map[string]any{
|
||||
"v2": newPath,
|
||||
"v3": newMethod,
|
||||
}).Error
|
||||
biz.ErrIsNil(err, "修改api失败")
|
||||
}
|
||||
|
||||
func GetPolicyPathByRoleId(roleKey string) (pathMaps []CasbinRule) {
|
||||
func GetPolicyPathByRoleId(tenantId, roleKey string) (pathMaps []CasbinRule) {
|
||||
e := Casbin()
|
||||
list := e.GetFilteredPolicy(0, roleKey)
|
||||
list := e.GetFilteredPolicy(0, tenantId, roleKey)
|
||||
for _, v := range list {
|
||||
pathMaps = append(pathMaps, CasbinRule{
|
||||
Path: v[1],
|
||||
Method: v[2],
|
||||
Path: v[2],
|
||||
Method: v[3],
|
||||
})
|
||||
}
|
||||
return pathMaps
|
||||
@@ -57,7 +56,7 @@ func Casbin() *casbin.SyncedEnforcer {
|
||||
once.Do(func() {
|
||||
a, err := gormadapter.NewAdapterByDB(global.Db)
|
||||
biz.ErrIsNil(err, "新建权限适配器失败")
|
||||
syncedEnforcer, err = casbin.NewSyncedEnforcer(config.Conf.Casbin.ModelPath, a)
|
||||
syncedEnforcer, err = casbin.NewSyncedEnforcer(global.Conf.Casbin.ModelPath, a)
|
||||
biz.ErrIsNil(err, "新建权限适配器失败")
|
||||
})
|
||||
_ = syncedEnforcer.LoadPolicy()
|
||||
|
||||
@@ -8,23 +8,19 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// 配置文件映射对象
|
||||
var Conf *Config
|
||||
|
||||
func init() {
|
||||
configFilePath := flag.String("c", "./config.yml", "配置文件路径,默认为可执行文件目录")
|
||||
flag.Parse()
|
||||
func InitConfig(configFilePath string) *Config {
|
||||
// 获取启动参数中,配置文件的绝对路径
|
||||
path, _ := filepath.Abs(*configFilePath)
|
||||
path, _ := filepath.Abs(configFilePath)
|
||||
startConfigParam = &CmdConfigParam{ConfigFilePath: path}
|
||||
// 读取配置文件信息
|
||||
yc := &Config{}
|
||||
if err := utils.LoadYml(startConfigParam.ConfigFilePath, yc); err != nil {
|
||||
panic(fmt.Sprintf("读取配置文件[%s]失败: %s", startConfigParam.ConfigFilePath, err.Error()))
|
||||
panic(any(fmt.Sprintf("读取配置文件[%s]失败: %s", startConfigParam.ConfigFilePath, err.Error())))
|
||||
}
|
||||
// 校验配置文件内容信息
|
||||
yc.Valid()
|
||||
Conf = yc
|
||||
return yc
|
||||
|
||||
}
|
||||
|
||||
// 启动配置参数
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/logger"
|
||||
"pandax/base/utils"
|
||||
"pandax/pkg/global"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
|
||||
@@ -42,10 +42,10 @@ func LogHandler(rc *ReqCtx) error {
|
||||
lfs[req.Method] = req.URL.Path
|
||||
|
||||
if err := rc.Err; err != nil {
|
||||
logger.Log.WithFields(lfs).Error(getErrMsg(rc, err))
|
||||
global.Log.WithFields(lfs).Error(getErrMsg(rc, err))
|
||||
return nil
|
||||
}
|
||||
logger.Log.WithFields(lfs).Info(getLogMsg(rc))
|
||||
global.Log.WithFields(lfs).Info(getLogMsg(rc))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package ctx
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/casbin"
|
||||
"pandax/pkg/global"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Permission struct {
|
||||
@@ -34,7 +37,8 @@ func PermissionHandler(rc *ReqCtx) error {
|
||||
if tokenStr == "" {
|
||||
return biz.PermissionErr
|
||||
}
|
||||
loginAccount, err := ParseToken(tokenStr)
|
||||
j := NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256)
|
||||
loginAccount, err := j.ParseToken(tokenStr)
|
||||
if err != nil || loginAccount == nil {
|
||||
return biz.PermissionErr
|
||||
}
|
||||
@@ -45,7 +49,8 @@ func PermissionHandler(rc *ReqCtx) error {
|
||||
}
|
||||
e := casbin.Casbin()
|
||||
// 判断策略中是否存在
|
||||
success, _ := e.Enforce(loginAccount.RoleKey, rc.GinCtx.Request.URL.Path, rc.GinCtx.Request.Method)
|
||||
tenantId := strconv.Itoa(int(rc.LoginAccount.TenantId))
|
||||
success, err := e.Enforce(tenantId, loginAccount.RoleKey, rc.GinCtx.Request.URL.Path, rc.GinCtx.Request.Method)
|
||||
if !success {
|
||||
return biz.CasbinErr
|
||||
}
|
||||
|
||||
@@ -2,17 +2,15 @@ package ctx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"pandax/base/config"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
jwtSecret = []byte(config.Conf.Jwt.Key)
|
||||
)
|
||||
|
||||
type Claims struct {
|
||||
UserId int64
|
||||
TenantId int64
|
||||
UserName string
|
||||
RoleId int64
|
||||
RoleKey string
|
||||
@@ -21,43 +19,116 @@ type Claims struct {
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
func CreateToken(claims Claims) (string, error) {
|
||||
|
||||
tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
token, err := tokenClaims.SignedString(jwtSecret)
|
||||
|
||||
return token, err
|
||||
type JWT struct {
|
||||
SignedKeyID string
|
||||
SignedKey []byte
|
||||
SignedMethod jwt.SigningMethod
|
||||
}
|
||||
|
||||
func ParseToken(token string) (*Claims, error) {
|
||||
tokenClaims, err := jwt.ParseWithClaims(token, &Claims{}, func(token *jwt.Token) (any, error) {
|
||||
return jwtSecret, nil
|
||||
})
|
||||
var (
|
||||
TokenExpired = errors.New("token is expired")
|
||||
TokenNotValidYet = errors.New("token not active yet")
|
||||
TokenMalformed = errors.New("that's not even a token")
|
||||
TokenInvalid = errors.New("couldn't handle this token")
|
||||
)
|
||||
|
||||
if tokenClaims != nil {
|
||||
if claims, ok := tokenClaims.Claims.(*Claims); ok && tokenClaims.Valid {
|
||||
return claims, nil
|
||||
func NewJWT(kid string, key []byte, method jwt.SigningMethod) *JWT {
|
||||
return &JWT{
|
||||
SignedKeyID: kid,
|
||||
SignedKey: key,
|
||||
SignedMethod: method,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateToken 创建一个token
|
||||
func (j *JWT) CreateToken(claims Claims) (string, error) {
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, &claims)
|
||||
var key interface{}
|
||||
if j.isEs() {
|
||||
v, err := jwt.ParseECPrivateKeyFromPEM(j.SignedKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
key = v
|
||||
} else if j.isRsOrPS() {
|
||||
v, err := jwt.ParseRSAPrivateKeyFromPEM(j.SignedKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
key = v
|
||||
} else if j.isHs() {
|
||||
key = j.SignedKey
|
||||
} else {
|
||||
return "", errors.New("unsupported sign method")
|
||||
}
|
||||
return token.SignedString(key)
|
||||
}
|
||||
|
||||
// ParseToken 解析 token
|
||||
func (j *JWT) ParseToken(tokenString string) (*Claims, error) {
|
||||
token, err := jwt.ParseWithClaims(tokenString, &Claims{}, func(token *jwt.Token) (i interface{}, e error) {
|
||||
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, fmt.Errorf("parse error")
|
||||
}
|
||||
return j.SignedKey, nil
|
||||
})
|
||||
if err != nil {
|
||||
if ve, ok := err.(*jwt.ValidationError); ok {
|
||||
if ve.Errors&jwt.ValidationErrorMalformed != 0 {
|
||||
return nil, TokenMalformed
|
||||
} else if ve.Errors&jwt.ValidationErrorExpired != 0 {
|
||||
// Token is expired
|
||||
return nil, TokenExpired
|
||||
} else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 {
|
||||
return nil, TokenNotValidYet
|
||||
} else {
|
||||
return nil, TokenInvalid
|
||||
}
|
||||
}
|
||||
}
|
||||
if token != nil {
|
||||
if claims, ok := token.Claims.(*Claims); ok && token.Valid {
|
||||
return claims, nil
|
||||
}
|
||||
return nil, TokenInvalid
|
||||
|
||||
} else {
|
||||
return nil, TokenInvalid
|
||||
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 更新token
|
||||
func RefreshToken(tokenString string) (string, error) {
|
||||
func (j *JWT) RefreshToken(tokenString string) (string, error) {
|
||||
jwt.TimeFunc = func() time.Time {
|
||||
return time.Unix(0, 0)
|
||||
}
|
||||
token, err := jwt.ParseWithClaims(tokenString, &Claims{}, func(token *jwt.Token) (any, error) {
|
||||
return jwtSecret, nil
|
||||
token, err := jwt.ParseWithClaims(tokenString, &Claims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return j.SignedKey, nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if claims, ok := token.Claims.(*Claims); ok && token.Valid {
|
||||
jwt.TimeFunc = time.Now
|
||||
claims.StandardClaims.ExpiresAt = time.Now().Add(1 * time.Hour).Unix()
|
||||
return CreateToken(*claims)
|
||||
claims.StandardClaims.ExpiresAt = time.Now().Unix() + 60*60*24*7
|
||||
return j.CreateToken(*claims)
|
||||
}
|
||||
return "", errors.New("Couldn't handle this token:")
|
||||
return "", TokenInvalid
|
||||
}
|
||||
|
||||
func (a *JWT) isEs() bool {
|
||||
return strings.HasPrefix(a.SignedMethod.Alg(), "ES")
|
||||
}
|
||||
|
||||
func (a *JWT) isRsOrPS() bool {
|
||||
isRs := strings.HasPrefix(a.SignedMethod.Alg(), "RS")
|
||||
isPs := strings.HasPrefix(a.SignedMethod.Alg(), "PS")
|
||||
return isRs || isPs
|
||||
}
|
||||
|
||||
func (a *JWT) isHs() bool {
|
||||
return strings.HasPrefix(a.SignedMethod.Alg(), "HS")
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/base/model"
|
||||
"pandax/pkg/global"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
Log *logrus.Logger // 日志
|
||||
Db *gorm.DB // gorm
|
||||
)
|
||||
@@ -4,24 +4,21 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var Log = logrus.New()
|
||||
|
||||
func init() {
|
||||
func InitLog(logConf *config.Log) *logrus.Logger {
|
||||
var Log = logrus.New()
|
||||
Log.SetFormatter(new(LogFormatter))
|
||||
Log.SetReportCaller(true)
|
||||
|
||||
logConf := config.Conf.Log
|
||||
// 如果不存在日志配置信息,则默认debug级别
|
||||
if logConf == nil {
|
||||
Log.SetLevel(logrus.DebugLevel)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// 根据配置文件设置日志级别
|
||||
@@ -44,8 +41,7 @@ func init() {
|
||||
|
||||
Log.Out = file
|
||||
}
|
||||
|
||||
global.Log = Log
|
||||
return Log
|
||||
}
|
||||
|
||||
type LogFormatter struct{}
|
||||
|
||||
@@ -5,9 +5,10 @@ type AppContext struct {
|
||||
|
||||
type LoginAccount struct {
|
||||
UserId int64
|
||||
TenantId int64
|
||||
RoleId int64
|
||||
DeptId int64
|
||||
PostId int64
|
||||
Username string
|
||||
Rolename string
|
||||
RoleKey string
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package model
|
||||
import (
|
||||
"fmt"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
"strconv"
|
||||
|
||||
"strings"
|
||||
@@ -48,7 +48,9 @@ func (m *Model) SetBaseInfo(account *LoginAccount) {
|
||||
func Tx(funcs ...func(db *gorm.DB) error) (err error) {
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
var err any
|
||||
err = recover()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
err = fmt.Errorf("%v", err)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
@@ -23,7 +22,7 @@ func GormInit(ty string) *gorm.DB {
|
||||
return nil
|
||||
}
|
||||
func GormMysql() *gorm.DB {
|
||||
m := config.Conf.Mysql
|
||||
m := global.Conf.Mysql
|
||||
if m == nil || m.Dbname == "" {
|
||||
global.Log.Panic("未找到数据库配置信息")
|
||||
return nil
|
||||
@@ -50,7 +49,7 @@ func GormMysql() *gorm.DB {
|
||||
}
|
||||
|
||||
func GormPostgresql() *gorm.DB {
|
||||
m := config.Conf.Postgresql
|
||||
m := global.Conf.Postgresql
|
||||
if m == nil || m.Dbname == "" {
|
||||
global.Log.Panic("未找到数据库配置信息")
|
||||
return nil
|
||||
|
||||
@@ -2,15 +2,14 @@ package starter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
)
|
||||
|
||||
func ConnRedis() *redis.Client {
|
||||
// 设置redis客户端
|
||||
redisConf := config.Conf.Redis
|
||||
redisConf := global.Conf.Redis
|
||||
if redisConf == nil {
|
||||
global.Log.Panic("未找到redis配置信息")
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package starter
|
||||
|
||||
import (
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RunWebServer(web *gin.Engine) {
|
||||
server := config.Conf.Server
|
||||
server := global.Conf.Server
|
||||
port := server.GetPort()
|
||||
if app := config.Conf.App; app != nil {
|
||||
if app := global.Conf.App; app != nil {
|
||||
global.Log.Infof("%s- Listening and serving HTTP on %s", app.GetAppInfo(), port)
|
||||
} else {
|
||||
global.Log.Infof("Listening and serving HTTP on %s", port)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"pandax/base/global"
|
||||
"regexp"
|
||||
"sync"
|
||||
)
|
||||
@@ -33,7 +32,6 @@ func GetRegexp(pattern string) (regex *regexp.Regexp, err error) {
|
||||
// it compiles the pattern and creates one.
|
||||
regex, err = regexp.Compile(pattern)
|
||||
if err != nil {
|
||||
global.Log.Warnf(`regexp.Compile failed for pattern "%s"`, pattern)
|
||||
return
|
||||
}
|
||||
// Cache the result object using writing lock.
|
||||
|
||||
@@ -3,7 +3,7 @@ package ws
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
29
go.mod
29
go.mod
@@ -7,8 +7,8 @@ require (
|
||||
github.com/go-redis/redis v6.15.9+incompatible
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
// ssh
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
|
||||
gopkg.in/yaml.v3 v3.0.0
|
||||
gorm.io/gorm v1.22.3
|
||||
)
|
||||
|
||||
@@ -20,13 +20,13 @@ require (
|
||||
github.com/casbin/gorm-adapter/v3 v3.4.6
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/didip/tollbooth v4.0.2+incompatible
|
||||
github.com/golang/protobuf v1.4.3 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||
github.com/json-iterator/go v1.1.11 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/kakuilan/kgo v0.1.8
|
||||
github.com/lib/pq v1.10.4
|
||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mojocn/base64Captcha v1.3.5
|
||||
github.com/mssola/user_agent v0.5.3
|
||||
github.com/onsi/ginkgo v1.16.4 // indirect
|
||||
@@ -39,13 +39,15 @@ require (
|
||||
github.com/swaggo/swag v1.7.6
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.33
|
||||
github.com/xuri/excelize/v2 v2.4.1
|
||||
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 // indirect
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
|
||||
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
|
||||
google.golang.org/protobuf v1.26.0-rc.1 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gorm.io/driver/mysql v1.2.0
|
||||
gorm.io/driver/postgres v1.2.3
|
||||
)
|
||||
|
||||
require github.com/spf13/cobra v1.5.0
|
||||
|
||||
require (
|
||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
|
||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
@@ -54,6 +56,7 @@ require (
|
||||
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
|
||||
github.com/brianvoe/gofakeit/v6 v6.0.2 // indirect
|
||||
github.com/denisenkom/go-mssqldb v0.11.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
@@ -66,7 +69,9 @@ require (
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/google/go-cmp v0.5.8 // indirect
|
||||
github.com/google/go-querystring v1.0.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.10.1 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
@@ -82,20 +87,24 @@ require (
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mailru/easyjson v0.7.6 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
|
||||
github.com/mozillazg/go-httpheader v0.2.1 // indirect
|
||||
github.com/onsi/gomega v1.10.1 // indirect
|
||||
github.com/richardlehane/mscfb v1.0.3 // indirect
|
||||
github.com/richardlehane/msoleps v1.0.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stretchr/testify v1.7.1 // indirect
|
||||
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3 // indirect
|
||||
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
|
||||
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 // indirect
|
||||
golang.org/x/mod v0.4.1 // indirect
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.0 // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
|
||||
gopkg.in/ini.v1 v1.66.4 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gorm.io/driver/sqlserver v1.2.1 // indirect
|
||||
gorm.io/plugin/dbresolver v1.1.0 // indirect
|
||||
|
||||
60
go.sum
60
go.sum
@@ -31,6 +31,7 @@ github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMe
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -43,8 +44,9 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
|
||||
github.com/didip/tollbooth v4.0.2+incompatible h1:fVSa33JzSz0hoh2NxpwZtksAzAgd7zjmGO20HCZtF4M=
|
||||
github.com/didip/tollbooth v4.0.2+incompatible/go.mod h1:A9b0665CE6l1KmzpDws2++elm/CsuWBMa5Jv4WY0PEY=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
|
||||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gin-contrib/gzip v0.0.3 h1:etUaeesHhEORpZMp18zoOhepboiWnFtXrBZxszWUn4k=
|
||||
github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc=
|
||||
@@ -103,13 +105,15 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
@@ -121,6 +125,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
|
||||
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
|
||||
@@ -185,8 +191,8 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF
|
||||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ=
|
||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kakuilan/kgo v0.1.8 h1:b9UfGYNbUpWjPheOEgu/MsWUVDNWbcSit6BbNsBAPl0=
|
||||
github.com/kakuilan/kgo v0.1.8/go.mod h1:S9driqss6OluzqiOfUx7xN8nw0H6bFu5v7c19P09RRc=
|
||||
@@ -220,14 +226,15 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
|
||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
|
||||
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||
github.com/mojocn/base64Captcha v1.3.5 h1:Qeilr7Ta6eDtG4S+tQuZ5+hO+QHbiGAJdi4PfoagaA0=
|
||||
@@ -279,6 +286,7 @@ github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
@@ -291,6 +299,10 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
||||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
@@ -299,8 +311,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E=
|
||||
github.com/swaggo/gin-swagger v1.3.3 h1:XHyYmeNVFG5PbyWHG4jXtxOm2P4kiZapDCWsyDDiQ/I=
|
||||
github.com/swaggo/gin-swagger v1.3.3/go.mod h1:ymsZuGpbbu+S7ZoQ49QPpZoDBj6uqhb8WizgQPVgWl0=
|
||||
@@ -343,16 +356,18 @@ golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWP
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
|
||||
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY=
|
||||
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
@@ -363,8 +378,9 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 h1:4CSI6oo7cOjJKajidEljs9h+uP0rRZBPPPhcCbj5mw8=
|
||||
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 h1:NWy5+hlRbC7HK+PmcXVUmW1IMyFce7to56IUvhUFm7Y=
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -395,8 +411,9 @@ golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI=
|
||||
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -428,16 +445,19 @@ golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618=
|
||||
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
@@ -446,8 +466,9 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
||||
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
|
||||
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4=
|
||||
gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -459,8 +480,9 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
|
||||
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.0.3/go.mod h1:twGxftLBlFgNVNakL7F+P/x9oYqoymG3YYT8cAfI9oI=
|
||||
gorm.io/driver/mysql v1.1.2/go.mod h1:4P/X9vSc3WTrhTLZ259cpFd6xKNYiSSdSZngkSBGIMM=
|
||||
gorm.io/driver/mysql v1.2.0 h1:l8+9VwjjyzEkw0PNPBOr2JHhLOGVk7XEnl5hk42bcvs=
|
||||
|
||||
73
main.go
73
main.go
@@ -1,28 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"pandax/apps/job/jobs"
|
||||
"pandax/base/config"
|
||||
"pandax/base/ctx"
|
||||
"pandax/base/global"
|
||||
"pandax/base/logger"
|
||||
"pandax/base/starter"
|
||||
"pandax/initialize"
|
||||
"pandax/middleware"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/initialize"
|
||||
"pandax/pkg/middleware"
|
||||
)
|
||||
|
||||
func main() {
|
||||
global.Db = starter.GormInit(config.Conf.Server.DbType)
|
||||
initialize.InitTable()
|
||||
// gin前置 函数
|
||||
ctx.UseAfterHandlerInterceptor(middleware.OperationHandler)
|
||||
// gin前置 函数
|
||||
ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler)
|
||||
// gin后置 函数
|
||||
ctx.UseAfterHandlerInterceptor(ctx.LogHandler)
|
||||
go func() {
|
||||
// 启动系统调度任务
|
||||
jobs.InitJob()
|
||||
jobs.Setup()
|
||||
}()
|
||||
starter.RunWebServer(initialize.InitRouter())
|
||||
var (
|
||||
configFile string
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "panda is the main component in the panda.",
|
||||
Short: `panda is go gin frame`,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
if configFile != "" {
|
||||
global.Conf = config.InitConfig(configFile)
|
||||
global.Log = logger.InitLog(global.Conf.Log)
|
||||
global.Db = starter.GormInit(global.Conf.Server.DbType)
|
||||
initialize.InitTable()
|
||||
} else {
|
||||
global.Log.Panic("请配置config")
|
||||
}
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
ctx.UseAfterHandlerInterceptor(middleware.OperationHandler)
|
||||
// gin前置 函数
|
||||
ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler)
|
||||
// gin后置 函数
|
||||
ctx.UseAfterHandlerInterceptor(ctx.LogHandler)
|
||||
go func() {
|
||||
// 启动系统调度任务
|
||||
jobs.InitJob()
|
||||
jobs.Setup()
|
||||
}()
|
||||
starter.RunWebServer(initialize.InitRouter())
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().StringVar(&configFile, "config", getEnvStr("PANDA_CONFIG", "./config.yml"), "panda config file path.")
|
||||
}
|
||||
|
||||
func getEnvStr(env string, defaultValue string) string {
|
||||
v := os.Getenv(env)
|
||||
if v == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
rootCmd.PrintErrf("panda root cmd execute: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
13
pkg/global/global.go
Normal file
13
pkg/global/global.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
"pandax/base/config"
|
||||
)
|
||||
|
||||
var (
|
||||
Log *logrus.Logger // 日志
|
||||
Db *gorm.DB // gorm
|
||||
Conf *config.Config
|
||||
)
|
||||
@@ -2,6 +2,7 @@ package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pandax/pkg/global"
|
||||
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
|
||||
@@ -13,8 +14,7 @@ import (
|
||||
resRouter "pandax/apps/resource/router"
|
||||
sysRouter "pandax/apps/system/router"
|
||||
|
||||
"pandax/base/config"
|
||||
"pandax/middleware"
|
||||
"pandax/pkg/middleware"
|
||||
|
||||
_ "pandax/docs"
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
|
||||
func InitRouter() *gin.Engine {
|
||||
// server配置
|
||||
serverConfig := config.Conf.Server
|
||||
serverConfig := global.Conf.Server
|
||||
gin.SetMode(serverConfig.Model)
|
||||
|
||||
var router = gin.New()
|
||||
@@ -1,22 +1,18 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
//"pandax/base/casbin"
|
||||
|
||||
devEntity "pandax/apps/develop/entity"
|
||||
jobEntity "pandax/apps/job/entity"
|
||||
logEntity "pandax/apps/log/entity"
|
||||
resSourceEntity "pandax/apps/resource/entity"
|
||||
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/base/biz"
|
||||
"pandax/base/config"
|
||||
"pandax/base/global"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
// 初始化时如果没有表创建表
|
||||
func InitTable() {
|
||||
m := config.Conf.Server
|
||||
m := global.Conf.Server
|
||||
if m.IsInitTable {
|
||||
biz.ErrIsNil(
|
||||
global.Db.AutoMigrate(
|
||||
@@ -44,6 +40,5 @@ func InitTable() {
|
||||
resSourceEntity.ResEmail{},
|
||||
),
|
||||
"初始化表失败")
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package middleware
|
||||
import (
|
||||
"github.com/didip/tollbooth"
|
||||
"github.com/gin-gonic/gin"
|
||||
"pandax/base/config"
|
||||
"pandax/pkg/global"
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
//限流中间件
|
||||
func Rate() gin.HandlerFunc {
|
||||
lmt := tollbooth.NewLimiter(config.Conf.Server.Rate.RateNum, nil)
|
||||
lmt := tollbooth.NewLimiter(global.Conf.Server.Rate.RateNum, nil)
|
||||
lmt.SetMessage("已经超出接口请求限制,稍后再试.")
|
||||
return func(c *gin.Context) {
|
||||
httpError := tollbooth.LimitByRequest(lmt, c.Writer, c.Request)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,11 @@
|
||||
[request_definition]
|
||||
r = sub, obj, act
|
||||
r = dom, sub, obj, act
|
||||
|
||||
[policy_definition]
|
||||
p = sub, obj, act
|
||||
p = dom, sub, obj, act
|
||||
|
||||
[policy_effect]
|
||||
e = some(where (p.eft == allow))
|
||||
|
||||
[matchers]
|
||||
m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.act == p.act || p.act == "*")
|
||||
m = r.dom == p.dom && r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && ( r.act == p.act || p.act == '*')
|
||||
Reference in New Issue
Block a user