Add application variables

This commit is contained in:
2025-10-26 00:08:55 +08:00
parent f41e3dac21
commit 8513cbce55
10 changed files with 1020 additions and 26 deletions

View File

@@ -1,7 +1,11 @@
package models
import (
"strings"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// API 接口表模型
@@ -13,6 +17,9 @@ type API struct {
// ID主键自增
ID uint `gorm:"primaryKey;comment:API接口ID自增主键" json:"id"`
// UUIDAPI接口唯一标识符自动生成
UUID string `gorm:"uniqueIndex;size:36;not null;comment:API接口UUID唯一标识符" json:"uuid"`
// API类型int型
APIType int `gorm:"not null;comment:API类型" json:"api_type"`
@@ -47,6 +54,14 @@ type API struct {
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
}
// BeforeCreate 在创建记录前自动生成UUID
func (api *API) BeforeCreate(tx *gorm.DB) error {
if api.UUID == "" {
api.UUID = strings.ToUpper(uuid.New().String())
}
return nil
}
// TableName 指定表名
func (API) TableName() string {
return "apis"