model

package
v0.0.0-...-fae7c5d Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Message string `json:"message"`
	Type    string `json:"type"`
	Param   string `json:"param"`
	Code    any    `json:"code"`
}

type GitHubOAuthResponse

type GitHubOAuthResponse struct {
	AccessToken string `json:"access_token"`
	Scope       string `json:"scope"`
	TokenType   string `json:"token_type"`
}

type GitHubUser

type GitHubUser struct {
	Login string `json:"login"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

func NewGitHubUser

func NewGitHubUser() *GitHubUser

type Log

type Log struct {
	Id                int    `json:"id"`
	UserId            int    `json:"user_id" gorm:"index"`
	CreatedAt         int64  `json:"created_at" gorm:"bigint;index:idx_created_at_type"`
	Type              int    `json:"type" gorm:"index:idx_created_at_type"`
	Content           string `json:"content"`
	Username          string `json:"username" gorm:"index:index_username_model_name,priority:2;default:''"`
	TokenName         string `json:"token_name" gorm:"index;default:''"`
	ModelName         string `json:"model_name" gorm:"index;index:index_username_model_name,priority:1;default:''"`
	Quota             int    `json:"quota" gorm:"default:0"`
	PromptTokens      int    `json:"prompt_tokens" gorm:"default:0"`
	CompletionTokens  int    `json:"completion_tokens" gorm:"default:0"`
	ChannelId         int    `json:"channel" gorm:"index"`
	RequestId         string `json:"request_id" gorm:"default:''"`
	ElapsedTime       int64  `json:"elapsed_time" gorm:"default:0"` // unit is ms
	IsStream          bool   `json:"is_stream" gorm:"default:false"`
	SystemPromptReset bool   `json:"system_prompt_reset" gorm:"default:false"`
}

type ManageRequest

type ManageRequest struct {
	Username string `json:"username"`
	Action   string `json:"action"`
}

func NewManageRequest

func NewManageRequest() *ManageRequest

type Option

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

type Token

type Token struct {
	Id           int    `json:"id"`
	UserId       int    `json:"user_id"`
	Key          string `json:"key" gorm:"type:char(48);uniqueIndex"`
	Status       int    `json:"status" gorm:"default:1"`
	Name         string `json:"name" gorm:"index" `
	CreatedTime  int64  `json:"created_time" gorm:"bigint"`
	AccessedTime int64  `json:"accessed_time" gorm:"bigint"`
	ExpiredTime  int64  `json:"expired_time" gorm:"bigint;default:-1"` // -1 means never expired
	// RemainQuota    int64   `json:"remain_quota" gorm:"bigint;default:0"`
	// UnlimitedQuota bool    `json:"unlimited_quota" gorm:"default:false"`
	UsedQuota int64 `json:"used_quota" gorm:"bigint;default:0"` // used quota
	// Models         *string `json:"models" gorm:"type:text"`            // allowed models
	Subnet *string `json:"subnet" gorm:"default:''"` // allowed subnet
}

func NewToken

func NewToken() *Token

func NewTokenById

func NewTokenById(id int) *Token

func NewTokenByUserId

func NewTokenByUserId(id int, uid int) *Token

type User

type User struct {
	Id               int    `json:"id"`
	Username         string `json:"username" gorm:"unique;index" validate:"max=12"`
	Password         string `json:"password" gorm:"not null;" validate:"min=8,max=20"`
	DisplayName      string `json:"display_name" gorm:"index" validate:"max=20"`
	Role             int    `json:"role" gorm:"type:int;default:1"`   // admin, util
	Status           int    `json:"status" gorm:"type:int;default:1"` // enabled, disabled
	Email            string `json:"email" gorm:"index" validate:"max=50"`
	GitHubId         string `json:"github_id" gorm:"column:github_id;index"`
	WeChatId         string `json:"wechat_id" gorm:"column:wechat_id;index"`
	LarkId           string `json:"lark_id" gorm:"column:lark_id;index"`
	OidcId           string `json:"oidc_id" gorm:"column:oidc_id;index"`
	VerificationCode string `json:"verification_code" gorm:"-:all"`                                    // this field is only for Email verification, don't save it to database!
	AccessToken      string `json:"access_token" gorm:"type:char(32);column:access_token;uniqueIndex"` // this token is for system management
	// Quota            int64  `json:"quota" gorm:"bigint;default:0"`
	UsedQuota int64 `json:"used_quota" gorm:"bigint;default:0;column:used_quota"` // used quota
	// RequestCount int    `json:"request_count" gorm:"type:int;default:0;"`             // request number
	// Group        string `json:"group" gorm:"type:varchar(32);default:'default'"`
	AffCode   string `json:"aff_code" gorm:"type:varchar(32);column:aff_code;uniqueIndex"`
	InviterId int    `json:"inviter_id" gorm:"type:int;column:inviter_id;index"`
}

User if you add sensitive fields, don't forget to clean them in setupLogin function. Otherwise, the sensitive information will be saved on local storage in plain text!

func FromJSON

func FromJSON(data string) (*User, error)

FromJSON 从 JSON 解析为 User

func NewUser

func NewUser() *User

func NewUserByEmail

func NewUserByEmail(key string) *User

func NewUserByGitHubId

func NewUserByGitHubId(key string) *User

func NewUserById

func NewUserById(id int) *User

func NewUserByLarkId

func NewUserByLarkId(key string) *User

func NewUserByOidcId

func NewUserByOidcId(key string) *User

func NewUserByUsername

func NewUserByUsername(key string) *User

func NewUserByWeChatId

func NewUserByWeChatId(key string) *User

func (*User) ToJSON

func (u *User) ToJSON() (string, error)

ToJSON 将 User 转换为 JSON 字符串

Jump to

Keyboard shortcuts

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