common

package
v0.0.0-...-7a8aca8 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRequestBodySize  = 1024 * 1024 * 50 // 50MB
	MaxResponseBodySize = 1024 * 1024 * 50 // 50MB
)

Variables

View Source
var (
	SQLitePath        = env.String("SQLITE_PATH", "aiproxy.db")
	SQLiteBusyTimeout = env.Int64("SQLITE_BUSY_TIMEOUT", 3000)
)
View Source
var (
	RDB          *redis.Client
	RedisEnabled = false
)
View Source
var ErrLimitedReaderExceeded = errors.New("limited reader exceeded")
View Source
var StartTime = time.Now().UnixMilli() // unit: millisecond
View Source
var UsingSQLite = false

Functions

func GetBodyLimit

func GetBodyLimit(body io.Reader, contentLength, n int64) ([]byte, error)

func GetLogFields

func GetLogFields() logrus.Fields

func GetLogger

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

func GetLoggerFromReq

func GetLoggerFromReq(req *http.Request) *logrus.Entry

func GetRequestBody

func GetRequestBody(req *http.Request) ([]byte, error)

func GetRequestBodyLimit

func GetRequestBodyLimit(req *http.Request, n int64) ([]byte, error)

func GetRequestBodyReusable

func GetRequestBodyReusable(req *http.Request) ([]byte, error)

func GetResponseBody

func GetResponseBody(resp *http.Response) ([]byte, error)

func GetResponseBodyLimit

func GetResponseBodyLimit(resp *http.Response, n int64) ([]byte, error)

func InitLog

func InitLog(l *log.Logger, debug bool)

func InitRedisClient

func InitRedisClient() (err error)

InitRedisClient This function is called after init()

func IsDBConnectionError

func IsDBConnectionError(err error) bool

IsDBConnectionError checks if the error is a database connection error using type-based error checking with errors.As, with string pattern fallback

func IsJSONContentType

func IsJSONContentType(ct string) bool

func LimitReader

func LimitReader(r io.Reader, n int64) io.Reader

func NeedColor

func NeedColor() bool

func NewLogger

func NewLogger() *logrus.Entry

func PutLogFields

func PutLogFields(fields logrus.Fields)

func RedisKey

func RedisKey(keys ...string) string

func RedisKeyPrefix

func RedisKeyPrefix() string

func RedisKeyf

func RedisKeyf(format string, args ...any) string

func SetLogger

func SetLogger(req *http.Request, entry *logrus.Entry)

func SetRequestBody

func SetRequestBody(req *http.Request, body []byte)

func ShortUUID

func ShortUUID() string

func TruncateByRune

func TruncateByRune[T ~string](s T, length int) T

func TruncateBytesByRune

func TruncateBytesByRune(b []byte, length int) []byte

func TruncateDuration

func TruncateDuration(d time.Duration) time.Duration

func UnmarshalRequest2NodeReusable

func UnmarshalRequest2NodeReusable(req *http.Request, path ...any) (ast.Node, error)

func UnmarshalRequestReusable

func UnmarshalRequestReusable(req *http.Request, v any) error

func UnmarshalResponse

func UnmarshalResponse(resp *http.Response, v any) error

func UnmarshalResponse2Node

func UnmarshalResponse2Node(resp *http.Response, path ...any) (ast.Node, error)

Types

type LimitedReader

type LimitedReader struct {
	R io.Reader
	N int64
}

func (*LimitedReader) Read

func (l *LimitedReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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