mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 02:04:09 +00:00
refactor🎨: 开放接口无需认证
This commit is contained in:
@@ -12,10 +12,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sysNoCheckRoleRouter(v1 *gin.RouterGroup ,authMiddleware *jwt.GinJWTMiddleware) {
|
func sysNoCheckRoleRouter(v1 *gin.RouterGroup ,authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
r := v1.Group("").Use(authMiddleware.MiddlewareFunc())
|
r1 := v1.Group("")
|
||||||
{
|
{
|
||||||
sys := apis.System{}
|
sys := apis.System{}
|
||||||
r.GET("/getCaptcha", sys.GenerateCaptchaHandler)
|
r1.GET("/getCaptcha", sys.GenerateCaptchaHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := v1.Group("").Use(authMiddleware.MiddlewareFunc())
|
||||||
|
{
|
||||||
gen := tools.Gen{}
|
gen := tools.Gen{}
|
||||||
r.GET("/gen/preview/:tableId", gen.Preview)
|
r.GET("/gen/preview/:tableId", gen.Preview)
|
||||||
r.GET("/gen/toproject/:tableId", gen.GenCode)
|
r.GET("/gen/toproject/:tableId", gen.GenCode)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func registerSysConfigRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMidd
|
|||||||
r1.GET("/:configKey", api.GetSysConfigByKEYForService)
|
r1.GET("/:configKey", api.GetSysConfigByKEYForService)
|
||||||
}
|
}
|
||||||
|
|
||||||
r2 := v1.Group("/app-config").Use(authMiddleware.MiddlewareFunc())
|
r2 := v1.Group("/app-config")
|
||||||
{
|
{
|
||||||
r2.GET("", api.GetSysConfigBySysApp)
|
r2.GET("", api.GetSysConfigBySysApp)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DemoEvn() gin.HandlerFunc {
|
func DemoEvn() gin.HandlerFunc {
|
||||||
@@ -11,8 +10,8 @@ func DemoEvn() gin.HandlerFunc {
|
|||||||
method := c.Request.Method
|
method := c.Request.Method
|
||||||
if method == "GET" ||
|
if method == "GET" ||
|
||||||
method == "OPTIONS" ||
|
method == "OPTIONS" ||
|
||||||
strings.Contains(c.Request.RequestURI, "/login") ||
|
c.Request.RequestURI == "/api/v1/login" ||
|
||||||
strings.Contains(c.Request.RequestURI, "/logout") {
|
c.Request.RequestURI == "/api/v1/logout" {
|
||||||
c.Next()
|
c.Next()
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func InitMiddleware(r *gin.Engine) {
|
|||||||
// 数据库链接
|
// 数据库链接
|
||||||
r.Use(WithContextDb)
|
r.Use(WithContextDb)
|
||||||
// 日志处理
|
// 日志处理
|
||||||
//r.Use(LoggerToFile())
|
r.Use(LoggerToFile())
|
||||||
// 自定义错误处理
|
// 自定义错误处理
|
||||||
r.Use(CustomError)
|
r.Use(CustomError)
|
||||||
// NoCache is a middleware function that appends headers
|
// NoCache is a middleware function that appends headers
|
||||||
@@ -26,7 +26,7 @@ func InitMiddleware(r *gin.Engine) {
|
|||||||
r.Use(Options)
|
r.Use(Options)
|
||||||
// Secure is a middleware function that appends security
|
// Secure is a middleware function that appends security
|
||||||
r.Use(Secure)
|
r.Use(Secure)
|
||||||
//r.Use(DemoEvn())
|
r.Use(DemoEvn())
|
||||||
// 链路追踪
|
// 链路追踪
|
||||||
//r.Use(middleware.Trace())
|
//r.Use(middleware.Trace())
|
||||||
sdk.Runtime.SetMiddleware(JwtTokenCheck, (*jwt.GinJWTMiddleware).MiddlewareFunc)
|
sdk.Runtime.SetMiddleware(JwtTokenCheck, (*jwt.GinJWTMiddleware).MiddlewareFunc)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
gaConfig "go-admin/config"
|
gaConfig "go-admin/config"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -80,6 +81,11 @@ func LoggerToFile() gin.HandlerFunc {
|
|||||||
statusCode := c.Writer.Status()
|
statusCode := c.Writer.Status()
|
||||||
// 请求IP
|
// 请求IP
|
||||||
clientIP := c.ClientIP()
|
clientIP := c.ClientIP()
|
||||||
|
|
||||||
|
|
||||||
|
fmt.Println("Headers:", c.Request.Header.Get("X-Real-IP"))
|
||||||
|
|
||||||
|
fmt.Println("clientIP:", clientIP)
|
||||||
// 执行时间
|
// 执行时间
|
||||||
latencyTime := endTime.Sub(startTime)
|
latencyTime := endTime.Sub(startTime)
|
||||||
// 日志格式
|
// 日志格式
|
||||||
|
|||||||
Reference in New Issue
Block a user