common

package
v0.0.0-...-7f9085f 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: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UsingSQLite     = false
	UsingPostgreSQL = false
	UsingMySQL      = false
)
View Source
var (
	SQLitePath        = "aiproxy.db"
	SQLiteBusyTimeout = env.Int("SQLITE_BUSY_TIMEOUT", 3000)
)
View Source
var (
	Port   = flag.Int("port", 3000, "the listening port")
	LogDir = flag.String("log-dir", "", "specify the log directory")
)
View Source
var (
	RDB          *redis.Client
	RedisEnabled = false
)
View Source
var StartTime = time.Now().UnixMilli() // unit: millisecond

Functions

func GetRequestBody

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

func Init

func Init()

func InitRedisClient

func InitRedisClient() (err error)

InitRedisClient This function is called after init()

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 UnmarshalBodyReusable

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

Types

type CustomEvent

type CustomEvent struct {
	Data  string
	Event string
	ID    string
	Retry uint
}

func (CustomEvent) Render

func (r CustomEvent) Render(w http.ResponseWriter) error

func (CustomEvent) WriteContentType

func (r CustomEvent) WriteContentType(w http.ResponseWriter)

type InMemoryRateLimiter

type InMemoryRateLimiter struct {
	// contains filtered or unexported fields
}

func (*InMemoryRateLimiter) Init

func (l *InMemoryRateLimiter) Init(expirationDuration time.Duration)

func (*InMemoryRateLimiter) Request

func (l *InMemoryRateLimiter) Request(key string, maxRequestNum int, duration time.Duration) bool

Request parameter duration's unit is seconds

type RateLimitWindow

type RateLimitWindow struct {
	// contains filtered or unexported fields
}

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