common

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRequestBodySize = 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 GetRequestBody

func GetRequestBody(req *http.Request) ([]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 RedisDel

func RedisDel(key string) error

func RedisGet

func RedisGet(key string) (string, error)

func RedisSet

func RedisSet(key string, value string, expiration time.Duration) error

func SetEventStreamHeaders

func SetEventStreamHeaders(c *gin.Context)

func TruncateByRune

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

func TruncateBytesByRune

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

func UnmarshalBody2Node

func UnmarshalBody2Node(req *http.Request) (ast.Node, error)

func UnmarshalBodyReusable

func UnmarshalBodyReusable(req *http.Request, v any) 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{}

Jump to

Keyboard shortcuts

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