提交 0c461a94 编写于 作者: C closetool

fix: casbin gorm-adapter has no sqlite3 support

Signed-off-by: Nclosetool <c299999999@qq.com>
上级 fd4af6e7
......@@ -82,7 +82,7 @@ func FindFile(c *gin.Context) {
global.GVA_LOG.Error("查找失败!", zap.Any("err", err))
response.FailWithMessage("查找失败", c)
} else {
response.OkWithDetailed(response.FileResponse{File: file},"查找成功", c)
response.OkWithDetailed(response.FileResponse{File: file}, "查找成功", c)
}
}
......@@ -122,7 +122,7 @@ func RemoveChunk(c *gin.Context) {
err = service.DeleteFileChunk(fileMd5, fileName, filePath)
if err != nil {
global.GVA_LOG.Error("缓存切片删除失败!", zap.Any("err", err))
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath},"缓存切片删除失败", c)
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除失败", c)
} else {
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
}
......
......@@ -69,7 +69,7 @@ func CheckFileMd5(c *gin.Context) {
response.OkWithDetailed(gin.H{
"chunks": chunks,
"isDone": isDone,
},"查询成功", c)
}, "查询成功", c)
}
}
......
......@@ -148,7 +148,6 @@ func GetAllApis(c *gin.Context) {
}
}
// @Tags SysApi
// @Summary 删除选中Api
// @Security ApiKeyAuth
......@@ -164,6 +163,6 @@ func DeleteApisByIds(c *gin.Context) {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功",c)
response.OkWithMessage("删除成功", c)
}
}
\ No newline at end of file
}
......@@ -51,4 +51,3 @@ func GetPolicyPathByAuthorityId(c *gin.Context) {
paths := service.GetPolicyPathByAuthorityId(casbin.AuthorityId)
response.OkWithDetailed(response.PolicyPathResponse{Paths: paths}, "获取成功", c)
}
......@@ -214,6 +214,6 @@ func GetMenuList(c *gin.Context) {
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
},"获取成功", c)
}, "获取成功", c)
}
}
\ No newline at end of file
}
......@@ -2,4 +2,4 @@ package config
type Excel struct {
Dir string `mapstructure:"dir" json:"dir" yaml:"dir"`
}
\ No newline at end of file
}
......@@ -14,4 +14,4 @@ type Mysql struct {
func (m *Mysql) Dsn() string {
return m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config
}
\ No newline at end of file
}
......@@ -4,4 +4,4 @@ type Redis struct {
DB int `mapstructure:"db" json:"db" yaml:"db"`
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"`
Password string `mapstructure:"password" json:"password" yaml:"password"`
}
\ No newline at end of file
}
......@@ -14,4 +14,4 @@ func initServer(address string, router *gin.Engine) server {
s.WriteTimeout = 10 * time.Second
s.MaxHeaderBytes = 1 << 20
return s
}
\ No newline at end of file
}
......@@ -16,4 +16,4 @@ func initServer(address string, router *gin.Engine) server {
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
}
\ No newline at end of file
}
......@@ -15,5 +15,5 @@ var (
GVA_CONFIG config.Server
GVA_VP *viper.Viper
//GVA_LOG *oplogging.Logger
GVA_LOG *zap.Logger
GVA_LOG *zap.Logger
)
......@@ -8,9 +8,8 @@ require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/casbin/casbin v1.9.1
github.com/casbin/casbin/v2 v2.11.0
github.com/casbin/gorm-adapter/v3 v3.0.2
github.com/casbin/casbin/v2 v2.25.6
github.com/casbin/gorm-adapter/v3 v3.2.5
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/fsnotify/fsnotify v1.4.9
......@@ -30,7 +29,6 @@ require (
github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible
github.com/lestrrat-go/strftime v1.0.3 // indirect
github.com/mailru/easyjson v0.7.1 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/mojocn/base64Captcha v1.3.1
github.com/onsi/ginkgo v1.7.0 // indirect
......@@ -42,8 +40,8 @@ require (
github.com/shirou/gopsutil v3.21.1+incompatible
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.1.1
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.0
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.6.7
......@@ -56,8 +54,6 @@ require (
google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gorm.io/driver/mysql v0.3.0
gorm.io/driver/mysql v1.0.1
gorm.io/gorm v1.20.9
)
replace github.com/casbin/gorm-adapter/v3 => github.com/casbin/gorm-adapter/v3 v3.0.2
......@@ -17,7 +17,7 @@ func Redis() {
if err != nil {
global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err))
} else {
global.GVA_LOG.Info("redis connect ping response:", zap.String("pong",pong))
global.GVA_LOG.Info("redis connect ping response:", zap.String("pong", pong))
global.GVA_REDIS = client
}
}
......@@ -2,7 +2,7 @@ package request
import "gin-vue-admin/model"
type SysDictionarySearch struct{
model.SysDictionary
PageInfo
}
\ No newline at end of file
type SysDictionarySearch struct {
model.SysDictionary
PageInfo
}
......@@ -2,7 +2,7 @@ package request
import "gin-vue-admin/model"
type SysDictionaryDetailSearch struct{
model.SysDictionaryDetail
PageInfo
}
\ No newline at end of file
type SysDictionaryDetailSearch struct {
model.SysDictionaryDetail
PageInfo
}
......@@ -14,5 +14,5 @@ type SysAuthority struct {
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`
Children []SysAuthority `json:"children" gorm:"-"`
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"`
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"`
}
......@@ -9,12 +9,12 @@ import (
func InitApiRouter(Router *gin.RouterGroup) {
ApiRouter := Router.Group("api").Use(middleware.OperationRecord())
{
ApiRouter.POST("createApi", v1.CreateApi) // 创建Api
ApiRouter.POST("deleteApi", v1.DeleteApi) // 删除Api
ApiRouter.POST("getApiList", v1.GetApiList) // 获取Api列表
ApiRouter.POST("getApiById", v1.GetApiById) // 获取单条Api消息
ApiRouter.POST("updateApi", v1.UpdateApi) // 更新api
ApiRouter.POST("getAllApis", v1.GetAllApis) // 获取所有api
ApiRouter.POST("createApi", v1.CreateApi) // 创建Api
ApiRouter.POST("deleteApi", v1.DeleteApi) // 删除Api
ApiRouter.POST("getApiList", v1.GetApiList) // 获取Api列表
ApiRouter.POST("getApiById", v1.GetApiById) // 获取单条Api消息
ApiRouter.POST("updateApi", v1.UpdateApi) // 更新api
ApiRouter.POST("getAllApis", v1.GetAllApis) // 获取所有api
ApiRouter.DELETE("deleteApisByIds", v1.DeleteApisByIds) // 删除选中api
}
}
......@@ -12,6 +12,6 @@ func InitSystemRouter(Router *gin.RouterGroup) {
SystemRouter.POST("getSystemConfig", v1.GetSystemConfig) // 获取配置文件内容
SystemRouter.POST("setSystemConfig", v1.SetSystemConfig) // 设置配置文件内容
SystemRouter.POST("getServerInfo", v1.GetServerInfo) // 获取服务器信息
SystemRouter.POST("reloadSystem", v1.ReloadSystem) // 重启服务
SystemRouter.POST("reloadSystem", v1.ReloadSystem) // 重启服务
}
}
......@@ -11,29 +11,29 @@ import (
func ParseInfoList2Excel(infoList []model.SysBaseMenu, filePath string) error {
excel := excelize.NewFile()
excel.SetSheetRow("Sheet1","A1",&[]string{"ID","路由Name","路由Path","是否隐藏","父节点","排序","文件名称"})
for i, menu := range infoList {
axis := fmt.Sprintf("A%d",i+2)
excel.SetSheetRow("Sheet1",axis,&[]interface{}{
menu.ID,
menu.Name,
menu.Path,
menu.Hidden,
menu.ParentId,
menu.Sort,
menu.Component,
})
}
excel.SetSheetRow("Sheet1", "A1", &[]string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"})
for i, menu := range infoList {
axis := fmt.Sprintf("A%d", i+2)
excel.SetSheetRow("Sheet1", axis, &[]interface{}{
menu.ID,
menu.Name,
menu.Path,
menu.Hidden,
menu.ParentId,
menu.Sort,
menu.Component,
})
}
excel.SaveAs(filePath)
return nil
}
func ParseExcel2InfoList() ([]model.SysBaseMenu, error) {
skipHeader := true
fixedHeader := []string{"ID","路由Name","路由Path","是否隐藏","父节点","排序","文件名称"}
file, err := excelize.OpenFile(global.GVA_CONFIG.Excel.Dir+"ExcelImport.xlsx")
fixedHeader := []string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"}
file, err := excelize.OpenFile(global.GVA_CONFIG.Excel.Dir + "ExcelImport.xlsx")
if err != nil {
return nil, err
return nil, err
}
menus := make([]model.SysBaseMenu, 0)
rows, err := file.Rows("Sheet1")
......@@ -63,11 +63,11 @@ func ParseExcel2InfoList() ([]model.SysBaseMenu, error) {
GVA_MODEL: global.GVA_MODEL{
ID: uint(id),
},
Name: row[1],
Path: row[2],
Hidden: hidden,
ParentId: row[4],
Sort: sort,
Name: row[1],
Path: row[2],
Hidden: hidden,
ParentId: row[4],
Sort: sort,
Component: row[6],
}
menus = append(menus, menu)
......@@ -88,4 +88,4 @@ func compareStrSlice(a, b []string) bool {
}
}
return true
}
\ No newline at end of file
}
......@@ -5,6 +5,7 @@ import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gorm.io/gorm"
)
......@@ -130,8 +131,6 @@ func UpdateApi(api model.SysApi) (err error) {
return err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteApis
//@description: 删除选中API
......@@ -139,7 +138,6 @@ func UpdateApi(api model.SysApi) (err error) {
//@return: err error
func DeleteApisByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.SysApi{},"id in ?",ids.Ids).Error
err = global.GVA_DB.Delete(&[]model.SysApi{}, "id in ?", ids.Ids).Error
return err
return
}
\ No newline at end of file
}
......@@ -5,11 +5,12 @@ import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"github.com/casbin/casbin/util"
"strings"
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/util"
gormadapter "github.com/casbin/gorm-adapter/v3"
_ "github.com/go-sql-driver/mysql"
"strings"
)
//@author: [piexlmax](https://github.com/piexlmax)
......@@ -58,7 +59,6 @@ func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod
//@param: authorityId string
//@return: pathMaps []request.CasbinInfo
func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) {
e := Casbin()
list := e.GetFilteredPolicy(0, authorityId)
......
......@@ -41,19 +41,18 @@ func SetSystemConfig(system model.System) (err error) {
func GetServerInfo() (server *utils.Server, err error) {
var s utils.Server
s.Os = utils.InitOS()
if s.Cpu, err = utils.InitCPU(); err != nil{
if s.Cpu, err = utils.InitCPU(); err != nil {
global.GVA_LOG.Error("func utils.InitCPU() Failed!", zap.String("err", err.Error()))
return &s, err
}
if s.Rrm, err = utils.InitRAM(); err != nil{
if s.Rrm, err = utils.InitRAM(); err != nil {
global.GVA_LOG.Error("func utils.InitRAM() Failed!", zap.String("err", err.Error()))
return &s, err
}
if s.Disk, err = utils.InitDisk(); err != nil{
if s.Disk, err = utils.InitDisk(); err != nil {
global.GVA_LOG.Error("func utils.InitDisk() Failed!", zap.String("err", err.Error()))
return &s, err
}
return &s, nil
}
......@@ -10,7 +10,6 @@ import (
"gorm.io/gorm"
)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Register
//@description: 用户注册
......@@ -125,8 +124,8 @@ func FindUserById(id int) (err error, user *model.SysUser) {
func FindUserByUuid(uuid string) (err error, user *model.SysUser) {
var u model.SysUser
if err = global.GVA_DB.Where("`uuid` = ?", uuid).First(&u).Error; err != nil{
if err = global.GVA_DB.Where("`uuid` = ?", uuid).First(&u).Error; err != nil {
return errors.New("用户不存在"), &u
}
return nil, &u
}
\ No newline at end of file
}
......@@ -88,8 +88,6 @@ var apis = []model.SysApi{
{global.GVA_MODEL{ID: 85, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/deleteApisByIds", "批量删除api", "api", "DELETE"},
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@description: sys_apis 表数据初始化
func (a *api) Init() error {
......
此差异已折叠。
......@@ -31,4 +31,4 @@ func (f *file) Init() error {
color.Info.Println("\n[Mysql] --> exa_file_upload_and_downloads 表初始数据成功!")
return nil
})
}
\ No newline at end of file
}
package utils
const (
ConfigEnv = "GVA_CONFIG"
ConfigEnv = "GVA_CONFIG"
ConfigFile = "config.yaml"
)
......@@ -39,7 +39,7 @@ func CreateDir(dirs ...string) (err error) {
global.GVA_LOG.Debug("create directory" + v)
err = os.MkdirAll(v, os.ModePerm)
if err != nil {
global.GVA_LOG.Error("create directory"+ v, zap.Any(" error:", err))
global.GVA_LOG.Error("create directory"+v, zap.Any(" error:", err))
}
}
}
......
......@@ -27,4 +27,4 @@ func GetWriteSyncer() (zapcore.WriteSyncer, error) {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
}
return zapcore.AddSync(fileWriter), err
}
\ No newline at end of file
}
......@@ -24,4 +24,4 @@ func GetWriteSyncer() (zapcore.WriteSyncer, error) {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
}
return zapcore.AddSync(fileWriter), err
}
\ No newline at end of file
}
......@@ -35,7 +35,6 @@ type Cpu struct {
Cores int `json:"cores"`
}
type Rrm struct {
UsedMB int `json:"usedMb"`
TotalMB int `json:"totalMb"`
......@@ -89,9 +88,9 @@ func InitCPU() (c Cpu, err error) {
//@return: r Rrm, err error
func InitRAM() (r Rrm, err error) {
if u, err := mem.VirtualMemory(); err != nil{
if u, err := mem.VirtualMemory(); err != nil {
return r, err
}else {
} else {
r.UsedMB = int(u.Used) / MB
r.TotalMB = int(u.Total) / MB
r.UsedPercent = int(u.UsedPercent)
......@@ -105,7 +104,7 @@ func InitRAM() (r Rrm, err error) {
//@return: d Disk, err error
func InitDisk() (d Disk, err error) {
if u, err := disk.Usage("/"); err != nil{
if u, err := disk.Usage("/"); err != nil {
return d, err
} else {
d.UsedMB = int(u.Used) / MB
......@@ -115,4 +114,4 @@ func InitDisk() (d Disk, err error) {
d.UsedPercent = int(u.UsedPercent)
}
return d, nil
}
\ No newline at end of file
}
package upload
import (
"errors"
"gin-vue-admin/global"
......
......@@ -60,7 +60,7 @@ func (*Qiniu) DeleteFile(key string) error {
mac := qbox.NewMac(global.GVA_CONFIG.Qiniu.AccessKey, global.GVA_CONFIG.Qiniu.SecretKey)
cfg := qiniuConfig()
bucketManager := storage.NewBucketManager(mac, cfg)
if err := bucketManager.Delete(global.GVA_CONFIG.Qiniu.Bucket, key); err != nil{
if err := bucketManager.Delete(global.GVA_CONFIG.Qiniu.Bucket, key); err != nil {
global.GVA_LOG.Error("function bucketManager.Delete() Filed", zap.Any("err", err.Error()))
return errors.New("function bucketManager.Delete() Filed, err:" + err.Error())
}
......@@ -76,7 +76,7 @@ func (*Qiniu) DeleteFile(key string) error {
func qiniuConfig() *storage.Config {
cfg := storage.Config{
UseHTTPS: global.GVA_CONFIG.Qiniu.UseHTTPS,
UseHTTPS: global.GVA_CONFIG.Qiniu.UseHTTPS,
UseCdnDomains: global.GVA_CONFIG.Qiniu.UseCdnDomains,
}
switch global.GVA_CONFIG.Qiniu.Zone { // 根据配置文件进行初始化空间对应的机房
......@@ -92,4 +92,4 @@ func qiniuConfig() *storage.Config {
cfg.Zone = &storage.ZoneXinjiapo
}
return &cfg
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册