mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
Add application variables
This commit is contained in:
@@ -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"`
|
||||
|
||||
// UUID:API接口唯一标识符,自动生成
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user