First commit
This commit is contained in:
32
backend/internal/model/api_key.go
Normal file
32
backend/internal/model/api_key.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ApiKey struct {
|
||||
ID int64 `gorm:"primaryKey" json:"id"`
|
||||
UserID int64 `gorm:"index;not null" json:"user_id"`
|
||||
Key string `gorm:"uniqueIndex;size:128;not null" json:"key"` // sk-xxx
|
||||
Name string `gorm:"size:100;not null" json:"name"`
|
||||
GroupID *int64 `gorm:"index" json:"group_id"`
|
||||
Status string `gorm:"size:20;default:active;not null" json:"status"` // active/disabled
|
||||
CreatedAt time.Time `gorm:"not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// 关联
|
||||
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
Group *Group `gorm:"foreignKey:GroupID" json:"group,omitempty"`
|
||||
}
|
||||
|
||||
func (ApiKey) TableName() string {
|
||||
return "api_keys"
|
||||
}
|
||||
|
||||
// IsActive 检查是否激活
|
||||
func (k *ApiKey) IsActive() bool {
|
||||
return k.Status == "active"
|
||||
}
|
||||
Reference in New Issue
Block a user