model

package
v0.0.0-...-bfbff3f Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncFrequency = time.Minute * 3
	TokenCacheKey = "token:%s"
	GroupCacheKey = "group:%s"
)
View Source
const (
	ChannelStatusUnknown          = 0
	ChannelStatusEnabled          = 1 // don't use 0, 0 is the default value!
	ChannelStatusManuallyDisabled = 2 // also don't use 0
	ChannelStatusAutoDisabled     = 3
)
View Source
const (
	GroupStatusEnabled  = 1 // don't use 0, 0 is the default value!
	GroupStatusDisabled = 2 // also don't use 0
)
View Source
const (
	TokenStatusEnabled   = 1 // don't use 0, 0 is the default value!
	TokenStatusDisabled  = 2 // also don't use 0
	TokenStatusExpired   = 3
	TokenStatusExhausted = 4
)
View Source
const (
	ErrChannelNotFound = "channel"
)
View Source
const (
	ErrGroupNotFound = "group"
)
View Source
const ErrModelConfigNotFound = "model config"
View Source
const (
	ErrTokenNotFound = "token"
)

Variables

View Source
var (
	DB    *gorm.DB
	LogDB *gorm.DB
)
View Source
var ErrUnknownOptionKey = errors.New("unknown option key")

Functions

func BatchInsertChannels

func BatchInsertChannels(channels []*Channel) error

func BatchRecordConsume

func BatchRecordConsume(
	requestID string,
	requestAt time.Time,
	group string,
	code int,
	channelID int,
	promptTokens int,
	completionTokens int,
	modelName string,
	tokenID int,
	tokenName string,
	amount float64,
	price float64,
	completionPrice float64,
	endpoint string,
	content string,
	mode int,
	requestDetail *RequestDetail,
) error

func CacheCheckModelConfig

func CacheCheckModelConfig(models []string) ([]string, []string)

func CacheDeleteGroup

func CacheDeleteGroup(id string) error

func CacheDeleteToken

func CacheDeleteToken(key string) error

func CacheGetEnabledChannelType2ModelConfigs

func CacheGetEnabledChannelType2ModelConfigs() map[int][]*ModelConfig

CacheGetEnabledChannelType2ModelConfigs returns a map of channel type to enabled model configs

func CacheGetEnabledModels

func CacheGetEnabledModels() []string

CacheGetEnabledModels returns a list of enabled model names

func CacheIncreaseTokenUsedAmount

func CacheIncreaseTokenUsedAmount(key string, amount float64) error

func CacheSetGroup

func CacheSetGroup(group *Group) error

func CacheSetToken

func CacheSetToken(token *Token) error

func CacheUpdateGroupQPM

func CacheUpdateGroupQPM(id string, qpm int64) error

func CacheUpdateGroupStatus

func CacheUpdateGroupStatus(id string, status int) error

func CacheUpdateTokenUsedAmount

func CacheUpdateTokenUsedAmount(key string, amount float64) error

func CacheUpdateTokenUsedAmountOnlyIncrease

func CacheUpdateTokenUsedAmountOnlyIncrease(key string, amount float64) error

func CheckModelConfig

func CheckModelConfig(models []string) ([]string, []string, error)

func ClearLastTestErrorAt

func ClearLastTestErrorAt(id int) error

func CloseDB

func CloseDB() error

func CreateConsumeError

func CreateConsumeError(requestID string, requestAt time.Time, group string, tokenName string, model string, content string, usedAmount float64, tokenID int) error

func CreateGroup

func CreateGroup(group *Group) error

func DeleteChannelByID

func DeleteChannelByID(id int) error

func DeleteChannelsByIDs

func DeleteChannelsByIDs(ids []int) error

func DeleteDisabledChannel

func DeleteDisabledChannel() error

func DeleteGroupByID

func DeleteGroupByID(id string) (err error)

func DeleteGroupLogs

func DeleteGroupLogs(groupID string) (int64, error)

func DeleteGroupTokenByID

func DeleteGroupTokenByID(groupID string, id int) (err error)

func DeleteGroupTokensByIDs

func DeleteGroupTokensByIDs(groupID string, ids []int) (err error)

func DeleteGroupsByIDs

func DeleteGroupsByIDs(ids []string) (err error)

func DeleteModelConfig

func DeleteModelConfig(model string) error

func DeleteModelConfigsByModels

func DeleteModelConfigsByModels(models []string) error

func DeleteOldLog

func DeleteOldLog(timestamp time.Time) (int64, error)

func DeleteTokenByID

func DeleteTokenByID(id int) (err error)

func DeleteTokensByIDs

func DeleteTokensByIDs(ids []int) (err error)

func DisableChannelByID

func DisableChannelByID(id int) error

func EnableChannelByID

func EnableChannelByID(id int) error

func GetEnabledModel2Channels

func GetEnabledModel2Channels() map[string][]*Channel

GetEnabledModel2Channels returns a map of model name to enabled channels

func GetTokenUsedAmount

func GetTokenUsedAmount(id int) (float64, error)

func GetTokenUsedAmountByKey

func GetTokenUsedAmountByKey(key string) (float64, error)

func HandleNotFound

func HandleNotFound(err error, errMsg ...string) error

func HandleUpdateResult

func HandleUpdateResult(result *gorm.DB, entityName string) error

Helper function to handle update results

func InitChannelCache

func InitChannelCache() error

InitChannelCache initializes the channel cache from database

func InitDB

func InitDB()

func InitLogDB

func InitLogDB()

func InitModelConfigCache

func InitModelConfigCache() error

func InitOptionMap

func InitOptionMap() error

func InsertToken

func InsertToken(token *Token, autoCreateGroup bool) error

func OnConflictDoNothing

func OnConflictDoNothing() *gorm.DB

func RecordConsumeLog

func RecordConsumeLog(
	requestID string,
	requestAt time.Time,
	group string,
	code int,
	channelID int,
	promptTokens int,
	completionTokens int,
	modelName string,
	tokenID int,
	tokenName string,
	amount float64,
	price float64,
	completionPrice float64,
	endpoint string,
	content string,
	mode int,
	requestDetail *RequestDetail,
) error

func SaveModelConfig

func SaveModelConfig(config *ModelConfig) error

func SaveModelConfigs

func SaveModelConfigs(configs []*ModelConfig) error

func SortModelConfigsFunc

func SortModelConfigsFunc(i, j *ModelConfig) int

func SumUsedQuota

func SumUsedQuota(startTimestamp time.Time, endTimestamp time.Time, modelName string, group string, tokenName string, channel int, endpoint string) (quota int64)

func SumUsedToken

func SumUsedToken(startTimestamp time.Time, endTimestamp time.Time, modelName string, group string, tokenName string, endpoint string) (token int)

func SyncChannelCache

func SyncChannelCache(ctx context.Context, wg *sync.WaitGroup, frequency time.Duration)

func SyncModelConfigCache

func SyncModelConfigCache(ctx context.Context, wg *sync.WaitGroup, frequency time.Duration)

func SyncOptions

func SyncOptions(ctx context.Context, wg *sync.WaitGroup, frequency time.Duration)

func UpdateChannel

func UpdateChannel(channel *Channel) error

func UpdateChannelStatusByID

func UpdateChannelStatusByID(id int, status int) error

func UpdateChannelUsedAmount

func UpdateChannelUsedAmount(id int, amount float64, requestCount int) error

func UpdateGroupQPM

func UpdateGroupQPM(id string, qpm int64) (err error)

func UpdateGroupRequestCount

func UpdateGroupRequestCount(id string, count int) error

func UpdateGroupStatus

func UpdateGroupStatus(id string, status int) (err error)

func UpdateGroupTokenName

func UpdateGroupTokenName(group string, id int, name string) (err error)

func UpdateGroupTokenStatus

func UpdateGroupTokenStatus(group string, id int, status int) (err error)

func UpdateGroupTokenStatusAndAccessedAt

func UpdateGroupTokenStatusAndAccessedAt(group string, id int, status int) (err error)

func UpdateGroupUsedAmount

func UpdateGroupUsedAmount(id string, amount float64) error

func UpdateGroupUsedAmountAndRequestCount

func UpdateGroupUsedAmountAndRequestCount(id string, amount float64, count int) error

func UpdateOption

func UpdateOption(key string, value string) error

func UpdateOptions

func UpdateOptions(options map[string]string) error

func UpdateToken

func UpdateToken(token *Token) (err error)

func UpdateTokenName

func UpdateTokenName(id int, name string) (err error)

func UpdateTokenStatus

func UpdateTokenStatus(id int, status int) (err error)

func UpdateTokenStatusAndAccessedAt

func UpdateTokenStatusAndAccessedAt(id int, status int) (err error)

func UpdateTokenUsedAmount

func UpdateTokenUsedAmount(id int, amount float64, requestCount int) (err error)

Types

type Channel

type Channel struct {
	CreatedAt        time.Time         `gorm:"index"                              json:"created_at"`
	AccessedAt       time.Time         `json:"accessed_at"`
	LastTestErrorAt  time.Time         `json:"last_test_error_at"`
	ChannelTests     []*ChannelTest    `gorm:"foreignKey:ChannelID;references:ID" json:"channel_tests"`
	BalanceUpdatedAt time.Time         `json:"balance_updated_at"`
	ModelMapping     map[string]string `gorm:"serializer:fastjson;type:text"      json:"model_mapping"`
	Config           ChannelConfig     `gorm:"serializer:fastjson;type:text"      json:"config"`
	Key              string            `gorm:"type:text;index"                    json:"key"`
	Name             string            `gorm:"index"                              json:"name"`
	BaseURL          string            `gorm:"index"                              json:"base_url"`
	Models           []string          `gorm:"serializer:fastjson;type:text"      json:"models"`
	Balance          float64           `json:"balance"`
	ID               int               `gorm:"primaryKey"                         json:"id"`
	UsedAmount       float64           `gorm:"index"                              json:"used_amount"`
	RequestCount     int               `gorm:"index"                              json:"request_count"`
	Status           int               `gorm:"default:1;index"                    json:"status"`
	Type             int               `gorm:"default:0;index"                    json:"type"`
	Priority         int32             `json:"priority"`
}

func CacheGetAllChannelByID

func CacheGetAllChannelByID(id int) (*Channel, bool)

func CacheGetAllChannels

func CacheGetAllChannels() []*Channel

func CacheGetEnabledChannelByID

func CacheGetEnabledChannelByID(id int) (*Channel, bool)

func CacheGetEnabledChannels

func CacheGetEnabledChannels() []*Channel

func CacheGetRandomSatisfiedChannel

func CacheGetRandomSatisfiedChannel(model string) (*Channel, error)

func GetAllChannels

func GetAllChannels(onlyDisabled bool, omitKey bool) (channels []*Channel, err error)

func GetChannelByID

func GetChannelByID(id int, omitKey bool) (*Channel, error)

func GetChannels

func GetChannels(startIdx int, num int, onlyDisabled bool, omitKey bool, id int, name string, key string, channelType int, baseURL string, order string) (channels []*Channel, total int64, err error)

func LoadChannelByID

func LoadChannelByID(id int) (*Channel, error)

func LoadChannels

func LoadChannels() ([]*Channel, error)

func LoadEnabledChannels

func LoadEnabledChannels() ([]*Channel, error)

func SearchChannels

func SearchChannels(keyword string, startIdx int, num int, onlyDisabled bool, omitKey bool, id int, name string, key string, channelType int, baseURL string, order string) (channels []*Channel, total int64, err error)

func (*Channel) BeforeDelete

func (c *Channel) BeforeDelete(tx *gorm.DB) (err error)

func (*Channel) BeforeSave

func (c *Channel) BeforeSave(tx *gorm.DB) (err error)

check model config exist

func (*Channel) MarshalJSON

func (c *Channel) MarshalJSON() ([]byte, error)

func (*Channel) UpdateBalance

func (c *Channel) UpdateBalance(balance float64) error

func (*Channel) UpdateModelTest

func (c *Channel) UpdateModelTest(testAt time.Time, model, actualModel string, mode int, took float64, success bool, response string, code int) (*ChannelTest, error)

type ChannelConfig

type ChannelConfig struct {
	Region            string `json:"region,omitempty"`
	SK                string `json:"sk,omitempty"`
	AK                string `json:"ak,omitempty"`
	UserID            string `json:"user_id,omitempty"`
	APIVersion        string `json:"api_version,omitempty"`
	Plugin            string `json:"plugin,omitempty"`
	VertexAIProjectID string `json:"vertex_ai_project_id,omitempty"`
	VertexAIADC       string `json:"vertex_ai_adc,omitempty"`
}

type ChannelTest

type ChannelTest struct {
	TestAt      time.Time `json:"test_at"`
	Model       string    `gorm:"primaryKey"   json:"model"`
	ActualModel string    `json:"actual_model"`
	Response    string    `gorm:"type:text"    json:"response"`
	ChannelName string    `json:"channel_name"`
	ChannelType int       `json:"channel_type"`
	ChannelID   int       `gorm:"primaryKey"   json:"channel_id"`
	Took        float64   `json:"took"`
	Success     bool      `json:"success"`
	Mode        int       `json:"mode"`
	Code        int       `json:"code"`
}

func (*ChannelTest) MarshalJSON

func (ct *ChannelTest) MarshalJSON() ([]byte, error)

type ConsumeError

type ConsumeError struct {
	RequestAt  time.Time       `gorm:"index;index:idx_consume_error_group_reqat,priority:2" json:"request_at"`
	CreatedAt  time.Time       `json:"created_at"`
	GroupID    string          `gorm:"index;index:idx_consume_error_group_reqat,priority:1" json:"group_id"`
	RequestID  string          `gorm:"index"                                                json:"request_id"`
	TokenName  EmptyNullString `gorm:"not null"                                             json:"token_name"`
	Model      string          `json:"model"`
	Content    string          `gorm:"type:text"                                            json:"content"`
	ID         int             `gorm:"primaryKey"                                           json:"id"`
	UsedAmount float64         `json:"used_amount"`
	TokenID    int             `json:"token_id"`
}

func SearchConsumeError

func SearchConsumeError(keyword string, requestID string, group string, tokenName string, model string, content string, usedAmount float64, tokenID int, page int, perPage int, order string) ([]*ConsumeError, int64, error)

func (*ConsumeError) MarshalJSON

func (c *ConsumeError) MarshalJSON() ([]byte, error)

type EmptyNullString

type EmptyNullString string

func (*EmptyNullString) Scan

func (ns *EmptyNullString) Scan(value any) error

Scan implements the [Scanner] interface.

func (EmptyNullString) String

func (ns EmptyNullString) String() string

func (EmptyNullString) Value

func (ns EmptyNullString) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Group

type Group struct {
	CreatedAt    time.Time `json:"created_at"`
	AccessedAt   time.Time `json:"accessed_at"`
	ID           string    `gorm:"primaryKey"         json:"id"`
	Tokens       []*Token  `gorm:"foreignKey:GroupID" json:"-"`
	Status       int       `gorm:"default:1;index"    json:"status"`
	UsedAmount   float64   `gorm:"index"              json:"used_amount"`
	QPM          int64     `gorm:"index"              json:"qpm"`
	RequestCount int       `gorm:"index"              json:"request_count"`
}

func GetGroupByID

func GetGroupByID(id string) (*Group, error)

func GetGroups

func GetGroups(startIdx int, num int, order string, onlyDisabled bool) (groups []*Group, total int64, err error)

func SearchGroup

func SearchGroup(keyword string, startIdx int, num int, order string, status int) (groups []*Group, total int64, err error)

func (*Group) BeforeDelete

func (g *Group) BeforeDelete(tx *gorm.DB) (err error)

func (*Group) MarshalJSON

func (g *Group) MarshalJSON() ([]byte, error)

func (*Group) ToGroupCache

func (g *Group) ToGroupCache() *GroupCache

type GroupCache

type GroupCache struct {
	ID     string `json:"-"      redis:"-"`
	Status int    `json:"status" redis:"st"`
	QPM    int64  `json:"qpm"    redis:"q"`
}

func CacheGetGroup

func CacheGetGroup(id string) (*GroupCache, error)

type Log

type Log struct {
	RequestDetail    *RequestDetail `` /* 157-byte string literal not displayed */
	RequestAt        time.Time      `` /* 143-byte string literal not displayed */
	CreatedAt        time.Time      `` /* 143-byte string literal not displayed */
	TokenName        string         `` /* 143-byte string literal not displayed */
	Endpoint         string         `` /* 141-byte string literal not displayed */
	Content          string         `` /* 140-byte string literal not displayed */
	GroupID          string         `` /* 138-byte string literal not displayed */
	Model            string         `` /* 138-byte string literal not displayed */
	RequestID        string         `` /* 143-byte string literal not displayed */
	Price            float64        `json:"price"`
	ID               int            `` /* 135-byte string literal not displayed */
	CompletionPrice  float64        `json:"completion_price"`
	TokenID          int            `` /* 141-byte string literal not displayed */
	UsedAmount       float64        `` /* 144-byte string literal not displayed */
	PromptTokens     int            `json:"prompt_tokens"`
	CompletionTokens int            `json:"completion_tokens"`
	ChannelID        int            `` /* 140-byte string literal not displayed */
	Code             int            `` /* 137-byte string literal not displayed */
	Mode             int            `json:"mode"`
}

func GetGroupLogs

func GetGroupLogs(group string, startTimestamp time.Time, endTimestamp time.Time, code int, modelName string, requestID string, tokenID int, tokenName string, startIdx int, num int, channelID int, endpoint string, content string, order string, mode int) (logs []*Log, total int64, err error)

func GetLogs

func GetLogs(startTimestamp time.Time, endTimestamp time.Time, code int, modelName string, group string, requestID string, tokenID int, tokenName string, startIdx int, num int, channelID int, endpoint string, content string, order string, mode int) (logs []*Log, total int64, err error)

func SearchGroupLogs

func SearchGroupLogs(group string, keyword string, page int, perPage int, code int, endpoint string, requestID string, tokenID int, tokenName string, modelName string, content string, startTimestamp time.Time, endTimestamp time.Time, channelID int, order string, mode int) (logs []*Log, total int64, err error)

func SearchLogs

func SearchLogs(keyword string, page int, perPage int, code int, endpoint string, groupID string, requestID string, tokenID int, tokenName string, modelName string, content string, startTimestamp time.Time, endTimestamp time.Time, channelID int, order string, mode int) (logs []*Log, total int64, err error)

func (*Log) MarshalJSON

func (l *Log) MarshalJSON() ([]byte, error)

type LogStatistic

type LogStatistic struct {
	Day              string `gorm:"column:day"`
	Model            string `gorm:"column:model"`
	RequestCount     int    `gorm:"column:request_count"`
	PromptTokens     int    `gorm:"column:prompt_tokens"`
	CompletionTokens int    `gorm:"column:completion_tokens"`
}

func SearchLogsByDayAndModel

func SearchLogsByDayAndModel(group string, start time.Time, end time.Time) (logStatistics []*LogStatistic, err error)

type ModelConfig

type ModelConfig struct {
	CreatedAt         time.Time              `gorm:"index;autoCreateTime"          json:"created_at"`
	UpdatedAt         time.Time              `gorm:"index;autoUpdateTime"          json:"updated_at"`
	Config            map[ModelConfigKey]any `gorm:"serializer:fastjson;type:text" json:"config,omitempty"`
	ImagePrices       map[string]float64     `gorm:"serializer:fastjson"           json:"image_prices"`
	Model             string                 `gorm:"primaryKey"                    json:"model"`
	Owner             ModelOwner             `gorm:"type:varchar(255);index"       json:"owner"`
	ImageMaxBatchSize int                    `json:"image_batch_size"`
	// relaymode/define.go
	Type        int     `json:"type"`
	InputPrice  float64 `json:"input_price"`
	OutputPrice float64 `json:"output_price"`
}

func CacheGetEnabledModelConfigs

func CacheGetEnabledModelConfigs() []*ModelConfig

CacheGetEnabledModelConfigs returns a list of enabled model configs

func CacheGetModelConfig

func CacheGetModelConfig(model string) (*ModelConfig, bool)

func GetAllModelConfigs

func GetAllModelConfigs() (configs []*ModelConfig, err error)

func GetModelConfig

func GetModelConfig(model string) (*ModelConfig, error)

func GetModelConfigs

func GetModelConfigs(startIdx int, num int, model string) (configs []*ModelConfig, total int64, err error)

func GetModelConfigsByModels

func GetModelConfigsByModels(models []string) (configs []*ModelConfig, err error)

func SearchModelConfigs

func SearchModelConfigs(keyword string, startIdx int, num int, model string, owner ModelOwner) (configs []*ModelConfig, total int64, err error)

func (*ModelConfig) MarshalJSON

func (c *ModelConfig) MarshalJSON() ([]byte, error)

type ModelConfigKey

type ModelConfigKey string
const (
	ModelConfigMaxContextTokensKey ModelConfigKey = "max_context_tokens"
	ModelConfigMaxInputTokensKey   ModelConfigKey = "max_input_tokens"
	ModelConfigMaxOutputTokensKey  ModelConfigKey = "max_output_tokens"
	ModelConfigToolChoiceKey       ModelConfigKey = "tool_choice"
	ModelConfigFunctionCallingKey  ModelConfigKey = "function_calling"
	ModelConfigSupportFormatsKey   ModelConfigKey = "support_formats"
	ModelConfigSupportVoicesKey    ModelConfigKey = "support_voices"
)

type ModelOwner

type ModelOwner string
const (
	ModelOwnerOpenAI      ModelOwner = "openai"
	ModelOwnerAlibaba     ModelOwner = "alibaba"
	ModelOwnerTencent     ModelOwner = "tencent"
	ModelOwnerXunfei      ModelOwner = "xunfei"
	ModelOwnerDeepSeek    ModelOwner = "deepseek"
	ModelOwnerMoonshot    ModelOwner = "moonshot"
	ModelOwnerMiniMax     ModelOwner = "minimax"
	ModelOwnerBaidu       ModelOwner = "baidu"
	ModelOwnerGoogle      ModelOwner = "google"
	ModelOwnerBAAI        ModelOwner = "baai"
	ModelOwnerFunAudioLLM ModelOwner = "funaudiollm"
	ModelOwnerDoubao      ModelOwner = "doubao"
	ModelOwnerFishAudio   ModelOwner = "fishaudio"
	ModelOwnerChatGLM     ModelOwner = "chatglm"
	ModelOwnerStabilityAI ModelOwner = "stabilityai"
	ModelOwnerNetease     ModelOwner = "netease"
	ModelOwnerAI360       ModelOwner = "ai360"
	ModelOwnerAnthropic   ModelOwner = "anthropic"
	ModelOwnerMeta        ModelOwner = "meta"
	ModelOwnerBaichuan    ModelOwner = "baichuan"
	ModelOwnerMistral     ModelOwner = "mistral"
	ModelOwnerOpenChat    ModelOwner = "openchat"
	ModelOwnerMicrosoft   ModelOwner = "microsoft"
	ModelOwnerDefog       ModelOwner = "defog"
	ModelOwnerNexusFlow   ModelOwner = "nexusflow"
	ModelOwnerCohere      ModelOwner = "cohere"
	ModelOwnerHuggingFace ModelOwner = "huggingface"
	ModelOwnerLingyiWanwu ModelOwner = "lingyiwanwu"
	ModelOwnerStepFun     ModelOwner = "stepfun"
)

type NotFoundError

type NotFoundError string

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Option

type Option struct {
	Key   string `gorm:"primaryKey" json:"key"`
	Value string `json:"value"`
}

func GetAllOption

func GetAllOption() ([]*Option, error)

type RequestDetail

type RequestDetail struct {
	CreatedAt    time.Time `gorm:"autoCreateTime" json:"-"`
	RequestBody  string    `gorm:"type:text"      json:"request_body"`
	ResponseBody string    `gorm:"type:text"      json:"response_body"`
	ID           int       `json:"id"`
	LogID        int       `json:"log_id"`
}

type Token

type Token struct {
	CreatedAt    time.Time       `json:"created_at"`
	ExpiredAt    time.Time       `json:"expired_at"`
	AccessedAt   time.Time       `gorm:"index"                                     json:"accessed_at"`
	Group        *Group          `gorm:"foreignKey:GroupID"                        json:"-"`
	Key          string          `gorm:"type:char(48);uniqueIndex"                 json:"key"`
	Name         EmptyNullString `gorm:"index;uniqueIndex:idx_group_name;not null" json:"name"`
	GroupID      string          `gorm:"index;uniqueIndex:idx_group_name"          json:"group"`
	Subnet       string          `json:"subnet"`
	Models       []string        `gorm:"serializer:fastjson;type:text"             json:"models"`
	Status       int             `gorm:"default:1;index"                           json:"status"`
	ID           int             `gorm:"primaryKey"                                json:"id"`
	Quota        float64         `json:"quota"`
	UsedAmount   float64         `gorm:"index"                                     json:"used_amount"`
	RequestCount int             `gorm:"index"                                     json:"request_count"`
}

func GetGroupTokenByID

func GetGroupTokenByID(group string, id int) (*Token, error)

func GetGroupTokens

func GetGroupTokens(group string, startIdx int, num int, order string, status int) (tokens []*Token, total int64, err error)

func GetTokenByID

func GetTokenByID(id int) (*Token, error)

func GetTokenByKey

func GetTokenByKey(key string) (*Token, error)

func GetTokens

func GetTokens(startIdx int, num int, order string, group string, status int) (tokens []*Token, total int64, err error)

func SearchGroupTokens

func SearchGroupTokens(group string, keyword string, startIdx int, num int, order string, status int, name string, key string) (tokens []*Token, total int64, err error)

func SearchTokens

func SearchTokens(keyword string, startIdx int, num int, order string, status int, name string, key string, group string) (tokens []*Token, total int64, err error)

func (*Token) MarshalJSON

func (t *Token) MarshalJSON() ([]byte, error)

func (*Token) ToTokenCache

func (t *Token) ToTokenCache() *TokenCache

type TokenCache

type TokenCache struct {
	ExpiredAt  redisTime        `json:"expired_at"  redis:"e"`
	Group      string           `json:"group"       redis:"g"`
	Key        string           `json:"-"           redis:"-"`
	Name       string           `json:"name"        redis:"n"`
	Subnet     string           `json:"subnet"      redis:"s"`
	Models     redisStringSlice `json:"models"      redis:"m"`
	ID         int              `json:"id"          redis:"i"`
	Status     int              `json:"status"      redis:"st"`
	Quota      float64          `json:"quota"       redis:"q"`
	UsedAmount float64          `json:"used_amount" redis:"u"`
}

func CacheGetTokenByKey

func CacheGetTokenByKey(key string) (*TokenCache, error)

func ValidateAndGetToken

func ValidateAndGetToken(key string) (token *TokenCache, err error)

Jump to

Keyboard shortcuts

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