mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-30 04:42:59 +00:00
整理requestId入口,兼容istio的header返回
This commit is contained in:
+8
-11
@@ -3,17 +3,17 @@ package tools
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TrafficKey = "X-Request-Id"
|
||||
|
||||
func CompareHashAndPassword(e string, p string) (bool, error) {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(e), []byte(p))
|
||||
if err != nil {
|
||||
@@ -56,15 +56,12 @@ func HasError(err error, msg string, code ...int) {
|
||||
|
||||
// GenerateMsgIDFromContext 生成msgID
|
||||
func GenerateMsgIDFromContext(c *gin.Context) string {
|
||||
var msgID string
|
||||
data, ok := c.Get("msgID")
|
||||
if !ok {
|
||||
msgID = uuid.New().String()
|
||||
c.Set("msgID", msgID)
|
||||
return msgID
|
||||
requestId := c.GetHeader(TrafficKey)
|
||||
if requestId == "" {
|
||||
fmt.Println("no", requestId)
|
||||
c.Header(TrafficKey, requestId)
|
||||
}
|
||||
msgID = cast.ToString(data)
|
||||
return msgID
|
||||
return requestId
|
||||
}
|
||||
|
||||
// GetOrm 获取orm连接
|
||||
|
||||
Reference in New Issue
Block a user