mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
Modify the UUID format to uppercase
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@ networkDev
|
|||||||
node.txt
|
node.txt
|
||||||
config.json
|
config.json
|
||||||
database.db
|
database.db
|
||||||
模板
|
logs
|
||||||
|
模板
|
||||||
@@ -278,7 +278,7 @@ func AppCreateHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// 确保UUID和Secret被设置(虽然BeforeCreate钩子应该处理这些,但为了保险起见)
|
// 确保UUID和Secret被设置(虽然BeforeCreate钩子应该处理这些,但为了保险起见)
|
||||||
if app.UUID == "" {
|
if app.UUID == "" {
|
||||||
app.UUID = uuid.New().String()
|
app.UUID = strings.ToUpper(uuid.New().String())
|
||||||
}
|
}
|
||||||
if app.Secret == "" {
|
if app.Secret == "" {
|
||||||
// 生成32位大写16进制随机字符
|
// 生成32位大写16进制随机字符
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -15,39 +16,39 @@ import (
|
|||||||
type API struct {
|
type API struct {
|
||||||
// ID:主键,自增
|
// ID:主键,自增
|
||||||
ID uint `gorm:"primaryKey;comment:API接口ID,自增主键" json:"id"`
|
ID uint `gorm:"primaryKey;comment:API接口ID,自增主键" json:"id"`
|
||||||
|
|
||||||
// API类型(int型)
|
// API类型(int型)
|
||||||
APIType int `gorm:"not null;comment:API类型" json:"api_type"`
|
APIType int `gorm:"not null;comment:API类型" json:"api_type"`
|
||||||
|
|
||||||
// API密钥
|
// API密钥
|
||||||
APIKey string `gorm:"size:255;not null;uniqueIndex;comment:API密钥,唯一标识" json:"api_key"`
|
APIKey string `gorm:"size:255;not null;uniqueIndex;comment:API密钥,唯一标识" json:"api_key"`
|
||||||
|
|
||||||
// 应用UUID,关联到App表
|
// 应用UUID,关联到App表
|
||||||
AppUUID string `gorm:"size:36;not null;index;comment:关联的应用UUID" json:"app_uuid"`
|
AppUUID string `gorm:"size:36;not null;index;comment:关联的应用UUID" json:"app_uuid"`
|
||||||
|
|
||||||
// 接口状态(1=启用,0=禁用)
|
// 接口状态(1=启用,0=禁用)
|
||||||
Status int `gorm:"default:1;not null;comment:接口状态,1=启用,0=禁用" json:"status"`
|
Status int `gorm:"default:1;not null;comment:接口状态,1=启用,0=禁用" json:"status"`
|
||||||
|
|
||||||
// 接口提交算法
|
// 接口提交算法
|
||||||
// 支持的算法:0=不加密,1=RC4,2=RSA,3=RSA(动态)
|
// 支持的算法:0=不加密,1=RC4,2=RSA,3=RSA(动态)
|
||||||
SubmitAlgorithm int `gorm:"default:0;not null;comment:提交算法,0=不加密,1=RC4,2=RSA,3=RSA动态" json:"submit_algorithm"`
|
SubmitAlgorithm int `gorm:"default:0;not null;comment:提交算法,0=不加密,1=RC4,2=RSA,3=RSA动态" json:"submit_algorithm"`
|
||||||
|
|
||||||
// 接口返回算法
|
// 接口返回算法
|
||||||
// 支持的算法:0=不加密,1=RC4,2=RSA,3=RSA(动态)
|
// 支持的算法:0=不加密,1=RC4,2=RSA,3=RSA(动态)
|
||||||
ReturnAlgorithm int `gorm:"default:0;not null;comment:返回算法,0=不加密,1=RC4,2=RSA,3=RSA动态" json:"return_algorithm"`
|
ReturnAlgorithm int `gorm:"default:0;not null;comment:返回算法,0=不加密,1=RC4,2=RSA,3=RSA动态" json:"return_algorithm"`
|
||||||
|
|
||||||
// 提交算法公钥(base64编码存储)
|
// 提交算法公钥(base64编码存储)
|
||||||
SubmitPublicKey string `gorm:"type:text;comment:提交算法公钥,base64编码" json:"submit_public_key"`
|
SubmitPublicKey string `gorm:"type:text;comment:提交算法公钥,base64编码" json:"submit_public_key"`
|
||||||
|
|
||||||
// 提交算法私钥(base64编码存储)
|
// 提交算法私钥(base64编码存储)
|
||||||
SubmitPrivateKey string `gorm:"type:text;comment:提交算法私钥,base64编码" json:"submit_private_key"`
|
SubmitPrivateKey string `gorm:"type:text;comment:提交算法私钥,base64编码" json:"submit_private_key"`
|
||||||
|
|
||||||
// 返回算法公钥(base64编码存储)
|
// 返回算法公钥(base64编码存储)
|
||||||
ReturnPublicKey string `gorm:"type:text;comment:返回算法公钥,base64编码" json:"return_public_key"`
|
ReturnPublicKey string `gorm:"type:text;comment:返回算法公钥,base64编码" json:"return_public_key"`
|
||||||
|
|
||||||
// 返回算法私钥(base64编码存储)
|
// 返回算法私钥(base64编码存储)
|
||||||
ReturnPrivateKey string `gorm:"type:text;comment:返回算法私钥,base64编码" json:"return_private_key"`
|
ReturnPrivateKey string `gorm:"type:text;comment:返回算法私钥,base64编码" json:"return_private_key"`
|
||||||
|
|
||||||
// 时间字段
|
// 时间字段
|
||||||
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
|
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
|
||||||
@@ -57,7 +58,7 @@ type API struct {
|
|||||||
func (api *API) BeforeCreate(tx *gorm.DB) error {
|
func (api *API) BeforeCreate(tx *gorm.DB) error {
|
||||||
if api.APIKey == "" {
|
if api.APIKey == "" {
|
||||||
// 生成唯一的API密钥
|
// 生成唯一的API密钥
|
||||||
api.APIKey = "api_" + uuid.New().String()
|
api.APIKey = "api_" + strings.ToUpper(uuid.New().String())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -69,9 +70,9 @@ func (API) TableName() string {
|
|||||||
|
|
||||||
// 算法类型常量
|
// 算法类型常量
|
||||||
const (
|
const (
|
||||||
AlgorithmNone = 0 // 不加密
|
AlgorithmNone = 0 // 不加密
|
||||||
AlgorithmRC4 = 1 // RC4
|
AlgorithmRC4 = 1 // RC4
|
||||||
AlgorithmRSA = 2 // RSA
|
AlgorithmRSA = 2 // RSA
|
||||||
AlgorithmRSADynamic = 3 // RSA(动态)
|
AlgorithmRSADynamic = 3 // RSA(动态)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -94,4 +95,4 @@ func GetAlgorithmName(algorithm int) string {
|
|||||||
// IsValidAlgorithm 验证算法类型是否有效
|
// IsValidAlgorithm 验证算法类型是否有效
|
||||||
func IsValidAlgorithm(algorithm int) bool {
|
func IsValidAlgorithm(algorithm int) bool {
|
||||||
return algorithm >= AlgorithmNone && algorithm <= AlgorithmRSADynamic
|
return algorithm >= AlgorithmNone && algorithm <= AlgorithmRSADynamic
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ type App struct {
|
|||||||
// BeforeCreate 在创建记录前自动生成UUID和密钥
|
// BeforeCreate 在创建记录前自动生成UUID和密钥
|
||||||
func (app *App) BeforeCreate(tx *gorm.DB) error {
|
func (app *App) BeforeCreate(tx *gorm.DB) error {
|
||||||
if app.UUID == "" {
|
if app.UUID == "" {
|
||||||
app.UUID = uuid.New().String()
|
app.UUID = strings.ToUpper(uuid.New().String())
|
||||||
}
|
}
|
||||||
if app.Secret == "" {
|
if app.Secret == "" {
|
||||||
// 生成32位大写16进制随机字符
|
// 生成32位大写16进制随机字符
|
||||||
|
|||||||
BIN
recharge.db
BIN
recharge.db
Binary file not shown.
Reference in New Issue
Block a user