结构调整添加cmd
This commit is contained in:
1 parent
f2829bfd98
commit
a2f4c00246
72 files changed
+838
-597
No files matched your search
+2
-2
@@ -1,9 +1,9 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
config2 "go-admin/config"
|
||||
"go-admin/handler"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
"go-admin/tools/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ func AuthInit() (*jwt.GinJWTMiddleware, error) {
|
||||
Key: []byte("secret key"),
|
||||
Timeout: time.Hour,
|
||||
MaxRefresh: time.Hour,
|
||||
IdentityKey: config2.ApplicationConfig.JwtSecret,
|
||||
IdentityKey: config.ApplicationConfig.JwtSecret,
|
||||
PayloadFunc: handler.PayloadFunc,
|
||||
IdentityHandler: handler.IdentityHandler,
|
||||
Authenticator: handler.Authenticator,
|
||||
|
||||
+3
-3
@@ -2,20 +2,20 @@ package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/config"
|
||||
config2 "go-admin/tools/config"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DemoEvn() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if config.ApplicationConfig.Env == "demo" {
|
||||
if config2.ApplicationConfig.Mode == "demo" {
|
||||
method := c.Request.Method
|
||||
if method == "GET" || method == "OPTIONS" || c.Request.RequestURI == "/login" || c.Request.RequestURI == "/api/v1/logout" {
|
||||
c.Next()
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 500,
|
||||
"msg": config.ApplicationConfig.EnvMsg,
|
||||
"msg": config2.ApplicationConfig.DemoMsg,
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
|
||||
+21
-23
@@ -4,10 +4,8 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go-admin/config"
|
||||
"go-admin/models"
|
||||
"go-admin/pkg/utils"
|
||||
"os"
|
||||
"go-admin/tools"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -18,20 +16,20 @@ var logger = logrus.New()
|
||||
// 日志记录到文件
|
||||
func LoggerToFile() gin.HandlerFunc {
|
||||
|
||||
//写入文件
|
||||
src, err := os.OpenFile(config.ApplicationConfig.LogPath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||
if err != nil {
|
||||
fmt.Println("err", err)
|
||||
}
|
||||
|
||||
//设置输出
|
||||
logger.Out = src
|
||||
|
||||
//设置日志级别
|
||||
logger.SetLevel(logrus.DebugLevel)
|
||||
|
||||
//设置日志格式
|
||||
logger.SetFormatter(&logrus.TextFormatter{})
|
||||
////写入文件
|
||||
//src, err := os.OpenFile(config2.LogConfig.Dir+"/", os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||
//if err != nil {
|
||||
// fmt.Println("err", err)
|
||||
//}
|
||||
//
|
||||
////设置输出
|
||||
//logger.Out = src
|
||||
//
|
||||
////设置日志级别
|
||||
//logger.SetLevel(logrus.DebugLevel)
|
||||
//
|
||||
////设置日志格式
|
||||
//logger.SetFormatter(&logrus.TextFormatter{})
|
||||
|
||||
return func(c *gin.Context) {
|
||||
// 开始时间
|
||||
@@ -84,9 +82,9 @@ func LoggerToFile() gin.HandlerFunc {
|
||||
menuList, _ := menu.Get()
|
||||
sysOperLog := models.SysOperLog{}
|
||||
sysOperLog.OperIp = clientIP
|
||||
sysOperLog.OperLocation = utils.GetLocation(clientIP)
|
||||
sysOperLog.Status = utils.IntToString(statusCode)
|
||||
sysOperLog.OperName = utils.GetUserName(c)
|
||||
sysOperLog.OperLocation = tools.GetLocation(clientIP)
|
||||
sysOperLog.Status = tools.IntToString(statusCode)
|
||||
sysOperLog.OperName = tools.GetUserName(c)
|
||||
sysOperLog.RequestMethod = c.Request.Method
|
||||
sysOperLog.OperUrl = reqUri
|
||||
if reqUri == "/login" {
|
||||
@@ -112,9 +110,9 @@ func LoggerToFile() gin.HandlerFunc {
|
||||
sysOperLog.Title = menuList[0].Title
|
||||
}
|
||||
b, _ := c.Get("body")
|
||||
sysOperLog.OperParam, _ = utils.StructToJsonStr(b)
|
||||
sysOperLog.CreateBy = utils.GetUserName(c)
|
||||
sysOperLog.OperTime = utils.GetCurrntTime()
|
||||
sysOperLog.OperParam, _ = tools.StructToJsonStr(b)
|
||||
sysOperLog.CreateBy = tools.GetUserName(c)
|
||||
sysOperLog.OperTime = tools.GetCurrntTime()
|
||||
sysOperLog.LatencyTime = (latencyTime).String()
|
||||
sysOperLog.UserAgent = c.Request.UserAgent()
|
||||
if c.Err() == nil {
|
||||
|
||||
@@ -2,10 +2,10 @@ package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/pkg"
|
||||
mycasbin "go-admin/pkg/casbin"
|
||||
"go-admin/pkg/jwtauth"
|
||||
_ "go-admin/pkg/jwtauth"
|
||||
"go-admin/tools"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
@@ -16,12 +16,12 @@ func AuthCheckRole() gin.HandlerFunc {
|
||||
data, _ := c.Get("JWT_PAYLOAD")
|
||||
v := data.(jwtauth.MapClaims)
|
||||
e, err := mycasbin.Casbin()
|
||||
pkg.HasError(err,"",500)
|
||||
tools.HasError(err,"",500)
|
||||
//检查权限
|
||||
res, err := e.Enforce(v["rolekey"], c.Request.URL.Path, c.Request.Method)
|
||||
log.Println("----------------", v["rolekey"], c.Request.URL.Path, c.Request.Method)
|
||||
|
||||
pkg.HasError(err,"",500)
|
||||
tools.HasError(err,"",500)
|
||||
|
||||
if res {
|
||||
c.Next()
|
||||
|
||||
Reference in new issue
Block a user