middleware

package
v0.0.0-...-03c30b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeAIPROXY = "aiproxy_error"
)

Variables

This section is empty.

Functions

func AdminAuth

func AdminAuth(c *gin.Context)

func CORS

func CORS() gin.HandlerFunc

func Distribute

func Distribute(c *gin.Context)

func ErrorResponse

func ErrorResponse(c *gin.Context, code int, message string)

func ForceRateLimit

func ForceRateLimit(ctx context.Context, key string, maxRequestNum int, duration time.Duration) bool

ignore redis error

func GetLogger

func GetLogger(c *gin.Context) *logrus.Entry

func GlobalAPIRateLimit

func GlobalAPIRateLimit(c *gin.Context)

func MemoryRateLimit

func MemoryRateLimit(_ context.Context, key string, maxRequestNum int, duration time.Duration) bool

func NewLog

func NewLog(l *logrus.Logger) gin.HandlerFunc

func NewLogger

func NewLogger() *logrus.Entry

func NewMetaByContext

func NewMetaByContext(c *gin.Context) *meta.Meta

func RateLimit

func RateLimit(ctx context.Context, key string, maxRequestNum int, duration time.Duration) (bool, error)

func RequestID

func RequestID(c *gin.Context)

func SetLogActualModelFields

func SetLogActualModelFields(fields logrus.Fields, actualModel string)

func SetLogChannelFields

func SetLogChannelFields(fields logrus.Fields, channel *meta.ChannelMeta)

func SetLogFieldsFromMeta

func SetLogFieldsFromMeta(m *meta.Meta, fields logrus.Fields)

func SetLogGroupFields

func SetLogGroupFields(fields logrus.Fields, group *model.GroupCache)

func SetLogIsChannelTestField

func SetLogIsChannelTestField(fields logrus.Fields, isChannelTest bool)

func SetLogModeField

func SetLogModeField(fields logrus.Fields, mode int)

func SetLogModelFields

func SetLogModelFields(fields logrus.Fields, model string)

func SetLogRequestIDField

func SetLogRequestIDField(fields logrus.Fields, requestID string)

func SetLogTokenFields

func SetLogTokenFields(fields logrus.Fields, token *model.TokenCache)

func SuccessResponse

func SuccessResponse(c *gin.Context, data any)

func TokenAuth

func TokenAuth(c *gin.Context)

Types

type APIResponse

type APIResponse struct {
	Data    any    `json:"data,omitempty"`
	Message string `json:"message,omitempty"`
	Success bool   `json:"success"`
}

type ModelRequest

type ModelRequest struct {
	Model string `form:"model" json:"model"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL