common

package
v0.0.0-...-53f416f Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	UsingSQLite     = false
	UsingPostgreSQL = false
	UsingMySQL      = false
)
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

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 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 InitRedisClient

func InitRedisClient() (err error)

InitRedisClient This function is called after init()

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 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 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)

type RequestBodyKey

type RequestBodyKey struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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