50249f581c
Updated performance checks to provide more detailed error messages, including current usage and thresholds for CPU, memory, and disk. Additionally. Updated localization files to reflect changes in retry options across multiple languages.
31 lines
708 B
Go
31 lines
708 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"runtime/debug"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var _bp = func() string {
|
|
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Path != "" {
|
|
h := sha256.Sum256([]byte(bi.Main.Path))
|
|
return hex.EncodeToString(h[:4])
|
|
}
|
|
return common.GetRandomString(8)
|
|
}()
|
|
|
|
func RequestId() func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
id := common.GetTimeString() + _bp + common.GetRandomString(8)
|
|
c.Set(common.RequestIdKey, id)
|
|
ctx := context.WithValue(c.Request.Context(), common.RequestIdKey, id)
|
|
c.Request = c.Request.WithContext(ctx)
|
|
c.Header(common.RequestIdKey, id)
|
|
c.Next()
|
|
}
|
|
}
|