From d256359681dc21a214c42eac423b1d067b94e6bf Mon Sep 17 00:00:00 2001 From: luorijun Date: Sat, 10 May 2025 16:59:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=A1=B9=E7=9B=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E5=B0=86=20orm=20=E5=92=8C=20rds=20=E5=8C=85?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=88=B0=20web/globals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- cmd/fill/main.go | 27 ++++++++++-- cmd/main/main.go | 35 +++------------ pkg/env/env.go | 10 ----- web/auth/session.go | 4 +- web/globals/alipay.go | 2 +- web/globals/aliyun.go | 2 +- web/globals/baiyin.go | 8 ++-- web/globals/init.go | 11 +++++ {pkg/orm => web/globals}/orm.go | 18 ++------ web/globals/orm/alias.go | 16 +++++++ {pkg => web/globals}/orm/localdatetime.go | 0 pkg/rds/rds.go => web/globals/redis.go | 14 +++--- web/globals/validator.go | 13 +++--- web/globals/wechatpay.go | 2 +- web/handlers/bill.go | 2 +- web/handlers/channel.go | 2 +- web/handlers/iden.go | 8 ++-- web/handlers/resource.go | 4 +- web/models/admin.gen.go | 20 ++++----- web/models/admin_role.gen.go | 6 +-- web/models/admin_role_link.gen.go | 8 ++-- web/models/admin_role_permission_link.gen.go | 8 ++-- web/models/announcement.gen.go | 8 ++-- web/models/bill.gen.go | 18 ++++---- web/models/channel.gen.go | 16 +++---- web/models/client.gen.go | 24 +++++----- web/models/client_permission_link.gen.go | 8 ++-- web/models/coupon.gen.go | 24 +++++----- web/models/logs_request.gen.go | 24 +++++----- web/models/node.gen.go | 18 ++++---- web/models/permission.gen.go | 6 +-- web/models/product.gen.go | 8 ++-- web/models/proxy.gen.go | 12 ++--- web/models/refund.gen.go | 20 ++++----- web/models/resource.gen.go | 8 ++-- web/models/resource_psr.gen.go | 16 ++++--- web/models/resource_pss.gen.go | 22 +++++----- web/models/trade.gen.go | 36 +++++++-------- web/models/user.gen.go | 34 +++++++-------- web/models/user_role.gen.go | 6 +-- web/models/user_role_link.gen.go | 8 ++-- web/models/user_role_permission_link.gen.go | 8 ++-- web/models/whitelist.gen.go | 10 ++--- web/services/auth.go | 2 +- web/services/channel.go | 7 ++- web/services/channel_test.go | 46 ++++++++++---------- web/services/id.go | 4 +- web/services/node.go | 8 ++-- web/services/resource.go | 12 ++--- web/services/session.go | 10 ++--- web/services/session_test.go | 2 +- web/services/transaction.go | 2 +- web/services/verifier.go | 17 ++++---- web/services/verifier_test.go | 2 +- {pkg => web}/testutil/db.go | 18 ++++---- {pkg => web}/testutil/redis.go | 4 +- {pkg => web}/testutil/remote.go | 0 {pkg => web}/testutil/tools.go | 0 web/web.go | 22 ++++++---- 60 files changed, 363 insertions(+), 349 deletions(-) create mode 100644 web/globals/init.go rename {pkg/orm => web/globals}/orm.go (75%) create mode 100644 web/globals/orm/alias.go rename {pkg => web/globals}/orm/localdatetime.go (100%) rename pkg/rds/rds.go => web/globals/redis.go (55%) rename {pkg => web}/testutil/db.go (76%) rename {pkg => web}/testutil/redis.go (89%) rename {pkg => web}/testutil/remote.go (100%) rename {pkg => web}/testutil/tools.go (100%) diff --git a/README.md b/README.md index b3396bc..70383f8 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ ### 长期 -- 将 orm 和 rds 迁移到 web/globals 中 +- 分离项目脚手架(env,logs,Server 结构体) - 业务代码和测试代码共用的控制变量可以优化为环境变量 - 考虑统计接口调用频率并通过接口展示 - 考虑登录时曾经输入过验证码的用户,登录成功后允许一段时间内免输验证码 diff --git a/cmd/fill/main.go b/cmd/fill/main.go index 3b676bb..c292539 100644 --- a/cmd/fill/main.go +++ b/cmd/fill/main.go @@ -1,11 +1,14 @@ package main import ( + "fmt" "golang.org/x/crypto/bcrypt" + "gorm.io/driver/postgres" + "gorm.io/gorm" + "gorm.io/gorm/schema" "log/slog" "platform/pkg/env" "platform/pkg/logs" - "platform/pkg/orm" client2 "platform/web/domains/client" proxy2 "platform/web/domains/proxy" m "platform/web/models" @@ -13,11 +16,29 @@ import ( ) func main() { + env.Init() logs.Init() - orm.Init() - err := q.Q.Transaction(func(tx *q.Query) (err error) { + // 初始化数据库连接 + dsn := fmt.Sprintf( + "host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Shanghai", + env.DbHost, env.DbUserName, env.DbPassword, env.DbName, env.DbPort, + ) + db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{ + NamingStrategy: schema.NamingStrategy{ + SingularTable: true, + }, + }) + if err != nil { + slog.Error("gorm 初始化数据库失败:", slog.Any("err", err)) + panic(err) + } + + q.SetDefault(db) + + // 填充数据 + err = q.Q.Transaction(func(tx *q.Query) (err error) { // 代理 err = q.Proxy. diff --git a/cmd/main/main.go b/cmd/main/main.go index e7b5d3d..93dfbda 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -6,8 +6,6 @@ import ( "os/signal" "platform/pkg/env" "platform/pkg/logs" - "platform/pkg/orm" - "platform/pkg/rds" "platform/web" "syscall" ) @@ -18,13 +16,11 @@ func main() { shutdown := make(chan os.Signal, 1) signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM) - // init 先后顺序有依赖 + // 初始化应用 env.Init() logs.Init() - orm.Init() - rds.Init() - // web 服务 + // 创建服务 app, err := web.New(&web.Config{ Listen: ":8080", }) @@ -33,10 +29,11 @@ func main() { return } + // 异步运行服务 errCh := make(chan error) defer close(errCh) go func() { - err = app.Run() + err := app.Run() if err != nil { slog.Error("Failed to run server", slog.Any("err", err)) errCh <- err @@ -45,32 +42,14 @@ func main() { }() // 关闭服务 - exit := false select { + case err = <-errCh: case <-shutdown: slog.Info("Received shutdown signal") app.Stop() - exit = true - case err := <-errCh: - if err != nil { - slog.Error("Server error", slog.Any("err", err)) - } + err = <-errCh } - - if exit { - err := <-errCh - if err != nil { - slog.Error("Server error", slog.Any("err", err)) - } - } - - // 关闭资源 - err = orm.Exit() if err != nil { - slog.Error("Failed to close database connection", slog.Any("err", err)) - } - err = rds.Exit() - if err != nil { - slog.Error("Failed to close redis connection", slog.Any("err", err)) + slog.Error("Server error", slog.Any("err", err)) } } diff --git a/pkg/env/env.go b/pkg/env/env.go index 0e7535c..230b075 100644 --- a/pkg/env/env.go +++ b/pkg/env/env.go @@ -268,7 +268,6 @@ var ( WechatPayPublicKey string WechatPayApiCert string WechatPayCallbackUrl string - WechatPayProduction = false ) func loadWechatPay() { @@ -312,15 +311,6 @@ func loadWechatPay() { if WechatPayCallbackUrl == "" { panic("环境变量 WECHATPAY_CALLBACK_URL 的值不能为空") } - - _WechatPayProduction := os.Getenv("WECHATPAY_PRODUCTION") - if _WechatPayProduction != "" { - value, err := strconv.ParseBool(_WechatPayProduction) - if err != nil { - panic("环境变量 WECHATPAY_PRODUCTION 的值不是布尔值") - } - WechatPayProduction = value - } } // endregion diff --git a/web/auth/session.go b/web/auth/session.go index 01baa9a..bee8a1f 100644 --- a/web/auth/session.go +++ b/web/auth/session.go @@ -6,13 +6,13 @@ import ( "errors" "fmt" "github.com/redis/go-redis/v9" - "platform/pkg/rds" + g "platform/web/globals" ) func find(ctx context.Context, token string) (*Context, error) { // 读取认证数据 - authJSON, err := rds.Client.Get(ctx, accessKey(token)).Result() + authJSON, err := g.Redis.Get(ctx, accessKey(token)).Result() if err != nil { if errors.Is(err, redis.Nil) { return nil, errors.New("invalid_token") diff --git a/web/globals/alipay.go b/web/globals/alipay.go index cbaad7e..01d158f 100644 --- a/web/globals/alipay.go +++ b/web/globals/alipay.go @@ -8,7 +8,7 @@ import ( var Alipay *alipay.Client -func InitAlipay() { +func initAlipay() { var client, err = alipay.New( env.AlipayAppId, env.AlipayAppPrivateKey, diff --git a/web/globals/aliyun.go b/web/globals/aliyun.go index b0819b9..1c325d9 100644 --- a/web/globals/aliyun.go +++ b/web/globals/aliyun.go @@ -14,7 +14,7 @@ type aliyunClient struct { Sms *sms.Client } -func InitAliyun() { +func initAliyun() { client, err := sms.NewClient(&openapi.Config{ AccessKeyId: &env.AliyunAccessKey, AccessKeySecret: &env.AliyunAccessKeySecret, diff --git a/web/globals/baiyin.go b/web/globals/baiyin.go index c1790a4..c124250 100644 --- a/web/globals/baiyin.go +++ b/web/globals/baiyin.go @@ -10,7 +10,6 @@ import ( "net/http/httputil" "net/url" "platform/pkg/env" - "platform/pkg/rds" "strconv" "strings" "time" @@ -36,7 +35,7 @@ type cloud struct { var Cloud CloudClient -func InitBaiyin() { +func initBaiyin() { Cloud = &cloud{ url: env.BaiyinAddr, } @@ -304,7 +303,7 @@ func (c *cloud) requestCloud(method string, url string, data string) (*http.Resp func (c *cloud) token(refresh bool) (string, error) { // redis 获取令牌 if !refresh { - token, err := rds.Client.Get(context.Background(), "remote:token").Result() + token, err := Redis.Get(context.Background(), "remote:token").Result() if err == nil && token != "" { return token, nil } @@ -347,7 +346,7 @@ func (c *cloud) token(refresh bool) (string, error) { // redis 设置令牌 token := result["token"].(string) - err = rds.Client.Set(context.Background(), "remote:token", token, 1*time.Hour).Err() + err = Redis.Set(context.Background(), "remote:token", token, 1*time.Hour).Err() if err != nil { return "", err } @@ -521,6 +520,7 @@ func (c *gateway) GatewayPortActive(param ...PortActiveReq) (map[string]PortData // endregion func (c *gateway) requestGateway(method string, url string, data string) (*http.Response, error) { + //goland:noinspection ALL url = fmt.Sprintf("http://%s:%s@%s:9990%s", c.username, c.password, c.url, url) req, err := http.NewRequest(method, url, strings.NewReader(data)) if err != nil { diff --git a/web/globals/init.go b/web/globals/init.go new file mode 100644 index 0000000..f1f694b --- /dev/null +++ b/web/globals/init.go @@ -0,0 +1,11 @@ +package globals + +func Init() { + initBaiyin() + initAlipay() + initWechatPay() + initAliyun() + initValidator() + initRedis() + initOrm() +} diff --git a/pkg/orm/orm.go b/web/globals/orm.go similarity index 75% rename from pkg/orm/orm.go rename to web/globals/orm.go index 1918204..6ecc2b5 100644 --- a/pkg/orm/orm.go +++ b/web/globals/orm.go @@ -1,10 +1,8 @@ -package orm +package globals import ( "fmt" "gorm.io/driver/postgres" - "gorm.io/gen" - "gorm.io/gen/field" "gorm.io/gorm" "gorm.io/gorm/schema" "log/slog" @@ -13,7 +11,7 @@ import ( var DB *gorm.DB -func Init() { +func initOrm() { // 连接数据库 dsn := fmt.Sprintf( @@ -43,7 +41,7 @@ func Init() { DB = db } -func Exit() error { +func ExitOrm() error { if DB != nil { conn, err := DB.DB() if err != nil { @@ -53,13 +51,3 @@ func Exit() error { } return nil } - -type WithAlias interface { - Alias() string -} - -func Alias(model WithAlias) func(db gen.Dao) gen.Dao { - return func(db gen.Dao) gen.Dao { - return db.Unscoped().Where(field.NewBool(model.Alias(), "deleted_at").IsNull()) - } -} diff --git a/web/globals/orm/alias.go b/web/globals/orm/alias.go new file mode 100644 index 0000000..b527f61 --- /dev/null +++ b/web/globals/orm/alias.go @@ -0,0 +1,16 @@ +package orm + +import ( + "gorm.io/gen" + "gorm.io/gen/field" +) + +type WithAlias interface { + Alias() string +} + +func Alias(model WithAlias) func(db gen.Dao) gen.Dao { + return func(db gen.Dao) gen.Dao { + return db.Unscoped().Where(field.NewBool(model.Alias(), "deleted_at").IsNull()) + } +} diff --git a/pkg/orm/localdatetime.go b/web/globals/orm/localdatetime.go similarity index 100% rename from pkg/orm/localdatetime.go rename to web/globals/orm/localdatetime.go diff --git a/pkg/rds/rds.go b/web/globals/redis.go similarity index 55% rename from pkg/rds/rds.go rename to web/globals/redis.go index 49b1fc1..01a0bda 100644 --- a/pkg/rds/rds.go +++ b/web/globals/redis.go @@ -1,4 +1,4 @@ -package rds +package globals import ( "net" @@ -7,19 +7,19 @@ import ( "github.com/redis/go-redis/v9" ) -var Client *redis.Client +var Redis *redis.Client -func Init() { - Client = redis.NewClient(&redis.Options{ +func initRedis() { + Redis = redis.NewClient(&redis.Options{ Addr: net.JoinHostPort(env.RedisHost, env.RedisPort), DB: env.RedisDb, Password: env.RedisPass, }) } -func Exit() error { - if Client != nil { - return Client.Close() +func ExitRedis() error { + if Redis != nil { + return Redis.Close() } return nil } diff --git a/web/globals/validator.go b/web/globals/validator.go index 303e2a8..fbebe98 100644 --- a/web/globals/validator.go +++ b/web/globals/validator.go @@ -2,23 +2,22 @@ package globals import ( "errors" - "strings" - "github.com/go-playground/locales/zh" ut "github.com/go-playground/universal-translator" "github.com/go-playground/validator/v10" zhtrans "github.com/go-playground/validator/v10/translations/zh" "github.com/gofiber/fiber/v2" + "strings" ) -var Validator *ValidatorHolder +var Validator *ValidatorClient -type ValidatorHolder struct { +type ValidatorClient struct { validator *validator.Validate translator ut.Translator } -func (v *ValidatorHolder) Validate(c *fiber.Ctx, data any) error { +func (v *ValidatorClient) Validate(c *fiber.Ctx, data any) error { if err := c.BodyParser(data); err != nil { return err @@ -39,7 +38,7 @@ func (v *ValidatorHolder) Validate(c *fiber.Ctx, data any) error { return nil } -func InitValidator() { +func initValidator() { var validate = validator.New(validator.WithRequiredStructEnabled()) var translator = ut.New(zh.New()).GetFallback() @@ -48,7 +47,7 @@ func InitValidator() { panic(err) } - Validator = &ValidatorHolder{ + Validator = &ValidatorClient{ validator: validate, translator: translator, } diff --git a/web/globals/wechatpay.go b/web/globals/wechatpay.go index b3c99fa..04f6f55 100644 --- a/web/globals/wechatpay.go +++ b/web/globals/wechatpay.go @@ -20,7 +20,7 @@ type WechatPayClient struct { Notify *notify.Handler } -func InitWechatPay() { +func initWechatPay() { // 加载商户私钥 private, err := base64.StdEncoding.DecodeString(env.WechatPayMchPrivateKey) diff --git a/web/handlers/bill.go b/web/handlers/bill.go index 8dd0810..4ff80dc 100644 --- a/web/handlers/bill.go +++ b/web/handlers/bill.go @@ -1,9 +1,9 @@ package handlers import ( - "platform/pkg/orm" "platform/web/auth" "platform/web/core" + "platform/web/globals/orm" q "platform/web/queries" "time" diff --git a/web/handlers/channel.go b/web/handlers/channel.go index 035c0ce..7351463 100644 --- a/web/handlers/channel.go +++ b/web/handlers/channel.go @@ -2,10 +2,10 @@ package handlers import ( "fmt" - "platform/pkg/orm" "platform/web/auth" "platform/web/core" channel2 "platform/web/domains/channel" + "platform/web/globals/orm" q "platform/web/queries" s "platform/web/services" "time" diff --git a/web/handlers/iden.go b/web/handlers/iden.go index 878e4fc..ee21909 100644 --- a/web/handlers/iden.go +++ b/web/handlers/iden.go @@ -5,9 +5,9 @@ import ( "errors" "fmt" "platform/pkg/env" - "platform/pkg/rds" "platform/pkg/u" "platform/web/auth" + g "platform/web/globals" m "platform/web/models" q "platform/web/queries" "platform/web/services" @@ -87,7 +87,7 @@ func Identify(c *fiber.Ctx) error { return err } - err = rds.Client.Set(c.Context(), idenKey(id), infoStr, 30*time.Minute).Err() + err = g.Redis.Set(c.Context(), idenKey(id), infoStr, 30*time.Minute).Err() if err != nil { return err } @@ -120,7 +120,7 @@ func IdentifyCallback(c *fiber.Ctx) error { } // 获取 token - infoStr, err := rds.Client.Get(c.Context(), idenKey(req.Id)).Result() + infoStr, err := g.Redis.Get(c.Context(), idenKey(req.Id)).Result() if err != nil { if errors.Is(err, redis.Nil) { return c.JSON(IdentifyCallbackRes{ @@ -179,7 +179,7 @@ func IdentifyCallback(c *fiber.Ctx) error { } // 删除认证中间状态 - err = rds.Client.Del(c.Context(), idenKey(req.Id)).Err() + err = g.Redis.Del(c.Context(), idenKey(req.Id)).Err() if err != nil { return err } diff --git a/web/handlers/resource.go b/web/handlers/resource.go index 39c4a28..6d096aa 100644 --- a/web/handlers/resource.go +++ b/web/handlers/resource.go @@ -1,12 +1,12 @@ package handlers import ( - "platform/pkg/orm" "platform/pkg/u" "platform/web/auth" "platform/web/core" resource2 "platform/web/domains/resource" trade2 "platform/web/domains/trade" + "platform/web/globals/orm" q "platform/web/queries" s "platform/web/services" "time" @@ -112,7 +112,7 @@ func AllResource(c *fiber.Ctx) error { // 查询套餐列表 pss := q.ResourcePss.As(q.Resource.Pss.Name()) - do := q.Resource.Debug(). + do := q.Resource. Joins(q.Resource.Pss). Where( q.Resource.UserID.Eq(authContext.Payload.Id), diff --git a/web/models/admin.gen.go b/web/models/admin.gen.go index 99528f7..95bb6df 100644 --- a/web/models/admin.gen.go +++ b/web/models/admin.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,17 +14,17 @@ const TableNameAdmin = "admin" // Admin mapped from table type Admin struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:管理员ID" json:"id"` // 管理员ID - Username string `gorm:"column:username;not null;comment:用户名" json:"username"` // 用户名 - Password string `gorm:"column:password;not null;comment:密码" json:"password"` // 密码 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:管理员ID" json:"id"` // 管理员ID + Username string `gorm:"column:username;not null;comment:用户名" json:"username"` // 用户名 + Password string `gorm:"column:password;not null;comment:密码" json:"password"` // 密码 Name string `gorm:"column:name;comment:真实姓名" json:"name"` // 真实姓名 - Avatar string `gorm:"column:avatar;comment:头像URL" json:"avatar"` // 头像URL + Avatar string `gorm:"column:avatar;comment:头像URL" json:"avatar"` // 头像URL Phone string `gorm:"column:phone;comment:手机号码" json:"phone"` // 手机号码 - Email string `gorm:"column:email;comment:邮箱" json:"email"` // 邮箱 - Status int32 `gorm:"column:status;not null;default:1;comment:状态:0-禁用,1-正常" json:"status"` // 状态:0-禁用,1-正常 - LastLogin orm.LocalDateTime `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间 - LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址 - LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理 + Email string `gorm:"column:email;comment:邮箱" json:"email"` // 邮箱 + Status int32 `gorm:"column:status;not null;default:1;comment:状态:0-禁用,1-正常" json:"status"` // 状态:0-禁用,1-正常 + LastLogin orm.LocalDateTime `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间 + LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址 + LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/admin_role.gen.go b/web/models/admin_role.gen.go index b383981..d3e5e57 100644 --- a/web/models/admin_role.gen.go +++ b/web/models/admin_role.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,11 +14,11 @@ const TableNameAdminRole = "admin_role" // AdminRole mapped from table type AdminRole struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:管理员角色ID" json:"id"` // 管理员角色ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:管理员角色ID" json:"id"` // 管理员角色ID Name string `gorm:"column:name;not null;comment:角色名称" json:"name"` // 角色名称 Description string `gorm:"column:description;comment:角色描述" json:"description"` // 角色描述 Active bool `gorm:"column:active;default:true;comment:是否激活" json:"active"` // 是否激活 - Sort int32 `gorm:"column:sort;comment:排序" json:"sort"` // 排序 + Sort int32 `gorm:"column:sort;comment:排序" json:"sort"` // 排序 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/admin_role_link.gen.go b/web/models/admin_role_link.gen.go index c239c76..33b888c 100644 --- a/web/models/admin_role_link.gen.go +++ b/web/models/admin_role_link.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,9 +14,9 @@ const TableNameAdminRoleLink = "admin_role_link" // AdminRoleLink mapped from table type AdminRoleLink struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID - AdminID int32 `gorm:"column:admin_id;not null;comment:管理员ID" json:"admin_id"` // 管理员ID - RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID + AdminID int32 `gorm:"column:admin_id;not null;comment:管理员ID" json:"admin_id"` // 管理员ID + RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/admin_role_permission_link.gen.go b/web/models/admin_role_permission_link.gen.go index e558a1a..e93423d 100644 --- a/web/models/admin_role_permission_link.gen.go +++ b/web/models/admin_role_permission_link.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,9 +14,9 @@ const TableNameAdminRolePermissionLink = "admin_role_permission_link" // AdminRolePermissionLink mapped from table type AdminRolePermissionLink struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID - RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID - PermissionID int32 `gorm:"column:permission_id;not null;comment:权限ID" json:"permission_id"` // 权限ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID + RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID + PermissionID int32 `gorm:"column:permission_id;not null;comment:权限ID" json:"permission_id"` // 权限ID CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/announcement.gen.go b/web/models/announcement.gen.go index 5242ea1..5103658 100644 --- a/web/models/announcement.gen.go +++ b/web/models/announcement.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,12 +14,12 @@ const TableNameAnnouncement = "announcement" // Announcement mapped from table type Announcement struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:公告ID" json:"id"` // 公告ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:公告ID" json:"id"` // 公告ID Title string `gorm:"column:title;not null;comment:公告标题" json:"title"` // 公告标题 Content string `gorm:"column:content;comment:公告内容" json:"content"` // 公告内容 - Type int32 `gorm:"column:type;not null;default:1;comment:公告类型:1-普通公告" json:"type"` // 公告类型:1-普通公告 + Type int32 `gorm:"column:type;not null;default:1;comment:公告类型:1-普通公告" json:"type"` // 公告类型:1-普通公告 Pin bool `gorm:"column:pin;not null;comment:是否置顶" json:"pin"` // 是否置顶 - Status int32 `gorm:"column:status;not null;default:1;comment:公告状态:0-禁用,1-正常" json:"status"` // 公告状态:0-禁用,1-正常 + Status int32 `gorm:"column:status;not null;default:1;comment:公告状态:0-禁用,1-正常" json:"status"` // 公告状态:0-禁用,1-正常 Sort int32 `gorm:"column:sort;not null;comment:公告排序" json:"sort"` // 公告排序 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 diff --git a/web/models/bill.gen.go b/web/models/bill.gen.go index ecadb91..ef14b8f 100644 --- a/web/models/bill.gen.go +++ b/web/models/bill.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,14 +14,14 @@ const TableNameBill = "bill" // Bill mapped from table type Bill struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:账单ID" json:"id"` // 账单ID - UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID - TradeID int32 `gorm:"column:trade_id;comment:订单ID" json:"trade_id"` // 订单ID - ResourceID int32 `gorm:"column:resource_id;comment:套餐ID" json:"resource_id"` // 套餐ID - RefundID int32 `gorm:"column:refund_id;comment:退款ID" json:"refund_id"` // 退款ID - BillNo string `gorm:"column:bill_no;not null;comment:易读账单号" json:"bill_no"` // 易读账单号 - Info string `gorm:"column:info;comment:产品可读信息" json:"info"` // 产品可读信息 - Type int32 `gorm:"column:type;not null;comment:账单类型:1-消费,2-退款,3-充值" json:"type"` // 账单类型:1-消费,2-退款,3-充值 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:账单ID" json:"id"` // 账单ID + UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID + TradeID int32 `gorm:"column:trade_id;comment:订单ID" json:"trade_id"` // 订单ID + ResourceID int32 `gorm:"column:resource_id;comment:套餐ID" json:"resource_id"` // 套餐ID + RefundID int32 `gorm:"column:refund_id;comment:退款ID" json:"refund_id"` // 退款ID + BillNo string `gorm:"column:bill_no;not null;comment:易读账单号" json:"bill_no"` // 易读账单号 + Info string `gorm:"column:info;comment:产品可读信息" json:"info"` // 产品可读信息 + Type int32 `gorm:"column:type;not null;comment:账单类型:1-消费,2-退款,3-充值" json:"type"` // 账单类型:1-消费,2-退款,3-充值 Amount float64 `gorm:"column:amount;not null;comment:账单金额" json:"amount"` // 账单金额 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 diff --git a/web/models/channel.gen.go b/web/models/channel.gen.go index fe8c654..68c5099 100644 --- a/web/models/channel.gen.go +++ b/web/models/channel.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,19 +14,19 @@ const TableNameChannel = "channel" // Channel mapped from table type Channel struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:通道ID" json:"id"` // 通道ID - UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID - ProxyID int32 `gorm:"column:proxy_id;not null;comment:代理ID" json:"proxy_id"` // 代理ID - NodeID int32 `gorm:"column:node_id;comment:节点ID" json:"node_id"` // 节点ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:通道ID" json:"id"` // 通道ID + UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID + ProxyID int32 `gorm:"column:proxy_id;not null;comment:代理ID" json:"proxy_id"` // 代理ID + NodeID int32 `gorm:"column:node_id;comment:节点ID" json:"node_id"` // 节点ID ProxyHost string `gorm:"column:proxy_host;not null;comment:代理地址" json:"proxy_host"` // 代理地址 ProxyPort int32 `gorm:"column:proxy_port;not null;comment:转发端口" json:"proxy_port"` // 转发端口 NodeHost string `gorm:"column:node_host;comment:节点地址" json:"node_host"` // 节点地址 Protocol int32 `gorm:"column:protocol;comment:协议类型:1-http,2-https,3-socks5" json:"protocol"` // 协议类型:1-http,2-https,3-socks5 - AuthIP bool `gorm:"column:auth_ip;not null;comment:IP认证" json:"auth_ip"` // IP认证 + AuthIP bool `gorm:"column:auth_ip;not null;comment:IP认证" json:"auth_ip"` // IP认证 UserHost string `gorm:"column:user_host;comment:用户地址" json:"user_host"` // 用户地址 AuthPass bool `gorm:"column:auth_pass;not null;comment:密码认证" json:"auth_pass"` // 密码认证 - Username string `gorm:"column:username;comment:用户名" json:"username"` // 用户名 - Password string `gorm:"column:password;comment:密码" json:"password"` // 密码 + Username string `gorm:"column:username;comment:用户名" json:"username"` // 用户名 + Password string `gorm:"column:password;comment:密码" json:"password"` // 密码 Expiration orm.LocalDateTime `gorm:"column:expiration;not null;comment:过期时间" json:"expiration"` // 过期时间 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 diff --git a/web/models/client.gen.go b/web/models/client.gen.go index 6ce6926..e19a9df 100644 --- a/web/models/client.gen.go +++ b/web/models/client.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,18 +14,18 @@ const TableNameClient = "client" // Client mapped from table type Client struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:客户端ID" json:"id"` // 客户端ID - ClientID string `gorm:"column:client_id;not null;comment:OAuth2客户端标识符" json:"client_id"` // OAuth2客户端标识符 - ClientSecret string `gorm:"column:client_secret;not null;comment:OAuth2客户端密钥" json:"client_secret"` // OAuth2客户端密钥 - RedirectURI string `gorm:"column:redirect_uri;comment:OAuth2 重定向URI" json:"redirect_uri"` // OAuth2 重定向URI - GrantCode bool `gorm:"column:grant_code;not null;comment:允许授权码授予" json:"grant_code"` // 允许授权码授予 - GrantClient bool `gorm:"column:grant_client;not null;comment:允许客户端凭证授予" json:"grant_client"` // 允许客户端凭证授予 - GrantRefresh bool `gorm:"column:grant_refresh;not null;comment:允许刷新令牌授予" json:"grant_refresh"` // 允许刷新令牌授予 - GrantPassword bool `gorm:"column:grant_password;not null;comment:允许密码授予" json:"grant_password"` // 允许密码授予 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:客户端ID" json:"id"` // 客户端ID + ClientID string `gorm:"column:client_id;not null;comment:OAuth2客户端标识符" json:"client_id"` // OAuth2客户端标识符 + ClientSecret string `gorm:"column:client_secret;not null;comment:OAuth2客户端密钥" json:"client_secret"` // OAuth2客户端密钥 + RedirectURI string `gorm:"column:redirect_uri;comment:OAuth2 重定向URI" json:"redirect_uri"` // OAuth2 重定向URI + GrantCode bool `gorm:"column:grant_code;not null;comment:允许授权码授予" json:"grant_code"` // 允许授权码授予 + GrantClient bool `gorm:"column:grant_client;not null;comment:允许客户端凭证授予" json:"grant_client"` // 允许客户端凭证授予 + GrantRefresh bool `gorm:"column:grant_refresh;not null;comment:允许刷新令牌授予" json:"grant_refresh"` // 允许刷新令牌授予 + GrantPassword bool `gorm:"column:grant_password;not null;comment:允许密码授予" json:"grant_password"` // 允许密码授予 Spec int32 `gorm:"column:spec;not null;comment:安全规范:1-native,2-browser,3-web,4-trusted" json:"spec"` // 安全规范:1-native,2-browser,3-web,4-trusted - Name string `gorm:"column:name;not null;comment:名称" json:"name"` // 名称 - Icon string `gorm:"column:icon;comment:图标URL" json:"icon"` // 图标URL - Status int32 `gorm:"column:status;not null;default:1;comment:状态:0-禁用,1-正常" json:"status"` // 状态:0-禁用,1-正常 + Name string `gorm:"column:name;not null;comment:名称" json:"name"` // 名称 + Icon string `gorm:"column:icon;comment:图标URL" json:"icon"` // 图标URL + Status int32 `gorm:"column:status;not null;default:1;comment:状态:0-禁用,1-正常" json:"status"` // 状态:0-禁用,1-正常 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/client_permission_link.gen.go b/web/models/client_permission_link.gen.go index ed53236..bbea687 100644 --- a/web/models/client_permission_link.gen.go +++ b/web/models/client_permission_link.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,9 +14,9 @@ const TableNameClientPermissionLink = "client_permission_link" // ClientPermissionLink mapped from table type ClientPermissionLink struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID - ClientID int32 `gorm:"column:client_id;not null;comment:客户端ID" json:"client_id"` // 客户端ID - PermissionID int32 `gorm:"column:permission_id;not null;comment:权限ID" json:"permission_id"` // 权限ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID + ClientID int32 `gorm:"column:client_id;not null;comment:客户端ID" json:"client_id"` // 客户端ID + PermissionID int32 `gorm:"column:permission_id;not null;comment:权限ID" json:"permission_id"` // 权限ID CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/coupon.gen.go b/web/models/coupon.gen.go index 083cf97..192903f 100644 --- a/web/models/coupon.gen.go +++ b/web/models/coupon.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,17 +14,17 @@ const TableNameCoupon = "coupon" // Coupon mapped from table type Coupon struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:优惠券ID" json:"id"` // 优惠券ID - UserID int32 `gorm:"column:user_id;comment:用户ID" json:"user_id"` // 用户ID - Code string `gorm:"column:code;not null;comment:优惠券代码" json:"code"` // 优惠券代码 - Remark string `gorm:"column:remark;comment:优惠券备注" json:"remark"` // 优惠券备注 - Amount float64 `gorm:"column:amount;not null;comment:优惠券金额" json:"amount"` // 优惠券金额 - MinAmount float64 `gorm:"column:min_amount;not null;comment:最低消费金额" json:"min_amount"` // 最低消费金额 - Status int32 `gorm:"column:status;not null;comment:优惠券状态:0-未使用,1-已使用,2-已过期" json:"status"` // 优惠券状态:0-未使用,1-已使用,2-已过期 - ExpireAt orm.LocalDateTime `gorm:"column:expire_at;comment:过期时间" json:"expire_at"` // 过期时间 - CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 - UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:优惠券ID" json:"id"` // 优惠券ID + UserID int32 `gorm:"column:user_id;comment:用户ID" json:"user_id"` // 用户ID + Code string `gorm:"column:code;not null;comment:优惠券代码" json:"code"` // 优惠券代码 + Remark string `gorm:"column:remark;comment:优惠券备注" json:"remark"` // 优惠券备注 + Amount float64 `gorm:"column:amount;not null;comment:优惠券金额" json:"amount"` // 优惠券金额 + MinAmount float64 `gorm:"column:min_amount;not null;comment:最低消费金额" json:"min_amount"` // 最低消费金额 + Status int32 `gorm:"column:status;not null;comment:优惠券状态:0-未使用,1-已使用,2-已过期" json:"status"` // 优惠券状态:0-未使用,1-已使用,2-已过期 + ExpireAt orm.LocalDateTime `gorm:"column:expire_at;comment:过期时间" json:"expire_at"` // 过期时间 + CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 + UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 } // TableName Coupon's table name diff --git a/web/models/logs_request.gen.go b/web/models/logs_request.gen.go index 2d65160..e12c48f 100644 --- a/web/models/logs_request.gen.go +++ b/web/models/logs_request.gen.go @@ -4,23 +4,25 @@ package models -import "platform/pkg/orm" +import ( + "platform/web/globals/orm" +) const TableNameLogsRequest = "logs_request" // LogsRequest mapped from table type LogsRequest struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:访问日志ID" json:"id"` // 访问日志ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:访问日志ID" json:"id"` // 访问日志ID Identity int32 `gorm:"column:identity;comment:访客身份:0-游客,1-用户,2-管理员,3-公共服务,4-安全服务,5-内部服务" json:"identity"` // 访客身份:0-游客,1-用户,2-管理员,3-公共服务,4-安全服务,5-内部服务 - Visitor int32 `gorm:"column:visitor;comment:访客ID" json:"visitor"` // 访客ID - IP string `gorm:"column:ip;not null;comment:IP地址" json:"ip"` // IP地址 - Ua string `gorm:"column:ua;comment:用户代理" json:"ua"` // 用户代理 - Method string `gorm:"column:method;not null;comment:请求方法" json:"method"` // 请求方法 - Path string `gorm:"column:path;not null;comment:请求路径" json:"path"` // 请求路径 - Latency string `gorm:"column:latency;comment:请求延迟" json:"latency"` // 请求延迟 - Status int32 `gorm:"column:status;not null;comment:响应状态码" json:"status"` // 响应状态码 - Error string `gorm:"column:error;comment:错误信息" json:"error"` // 错误信息 - Time orm.LocalDateTime `gorm:"column:time;default:CURRENT_TIMESTAMP;comment:请求时间" json:"time"` // 请求时间 + Visitor int32 `gorm:"column:visitor;comment:访客ID" json:"visitor"` // 访客ID + IP string `gorm:"column:ip;not null;comment:IP地址" json:"ip"` // IP地址 + Ua string `gorm:"column:ua;comment:用户代理" json:"ua"` // 用户代理 + Method string `gorm:"column:method;not null;comment:请求方法" json:"method"` // 请求方法 + Path string `gorm:"column:path;not null;comment:请求路径" json:"path"` // 请求路径 + Latency string `gorm:"column:latency;comment:请求延迟" json:"latency"` // 请求延迟 + Status int32 `gorm:"column:status;not null;comment:响应状态码" json:"status"` // 响应状态码 + Error string `gorm:"column:error;comment:错误信息" json:"error"` // 错误信息 + Time orm.LocalDateTime `gorm:"column:time;default:CURRENT_TIMESTAMP;comment:请求时间" json:"time"` // 请求时间 } // TableName LogsRequest's table name diff --git a/web/models/node.gen.go b/web/models/node.gen.go index 90f1375..86fa5fe 100644 --- a/web/models/node.gen.go +++ b/web/models/node.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,18 +14,18 @@ const TableNameNode = "node" // Node mapped from table type Node struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:节点ID" json:"id"` // 节点ID - ProxyID int32 `gorm:"column:proxy_id;comment:代理ID" json:"proxy_id"` // 代理ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:节点ID" json:"id"` // 节点ID + ProxyID int32 `gorm:"column:proxy_id;comment:代理ID" json:"proxy_id"` // 代理ID Version int32 `gorm:"column:version;not null;comment:节点版本" json:"version"` // 节点版本 Name string `gorm:"column:name;not null;comment:节点名称" json:"name"` // 节点名称 Host string `gorm:"column:host;not null;comment:节点地址" json:"host"` // 节点地址 - Isp int32 `gorm:"column:isp;not null;comment:运营商:0-未知,1-电信,2-联通,3-移动" json:"isp"` // 运营商:0-未知,1-电信,2-联通,3-移动 - Prov string `gorm:"column:prov;not null;comment:省份" json:"prov"` // 省份 - City string `gorm:"column:city;not null;comment:城市" json:"city"` // 城市 + Isp int32 `gorm:"column:isp;not null;comment:运营商:0-未知,1-电信,2-联通,3-移动" json:"isp"` // 运营商:0-未知,1-电信,2-联通,3-移动 + Prov string `gorm:"column:prov;not null;comment:省份" json:"prov"` // 省份 + City string `gorm:"column:city;not null;comment:城市" json:"city"` // 城市 ProxyPort int32 `gorm:"column:proxy_port;comment:代理端口" json:"proxy_port"` // 代理端口 - Status int32 `gorm:"column:status;not null;comment:节点状态:0-离线,1-正常" json:"status"` // 节点状态:0-离线,1-正常 - Rtt int32 `gorm:"column:rtt;comment:延迟" json:"rtt"` // 延迟 - Loss int32 `gorm:"column:loss;comment:丢包率" json:"loss"` // 丢包率 + Status int32 `gorm:"column:status;not null;comment:节点状态:0-离线,1-正常" json:"status"` // 节点状态:0-离线,1-正常 + Rtt int32 `gorm:"column:rtt;comment:延迟" json:"rtt"` // 延迟 + Loss int32 `gorm:"column:loss;comment:丢包率" json:"loss"` // 丢包率 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/permission.gen.go b/web/models/permission.gen.go index 7b023ff..0f55286 100644 --- a/web/models/permission.gen.go +++ b/web/models/permission.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,8 +14,8 @@ const TableNamePermission = "permission" // Permission mapped from table type Permission struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:权限ID" json:"id"` // 权限ID - ParentID int32 `gorm:"column:parent_id;comment:父权限ID" json:"parent_id"` // 父权限ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:权限ID" json:"id"` // 权限ID + ParentID int32 `gorm:"column:parent_id;comment:父权限ID" json:"parent_id"` // 父权限ID Name string `gorm:"column:name;not null;comment:权限名称" json:"name"` // 权限名称 Description string `gorm:"column:description;comment:权限描述" json:"description"` // 权限描述 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 diff --git a/web/models/product.gen.go b/web/models/product.gen.go index 1d87ab5..db2475c 100644 --- a/web/models/product.gen.go +++ b/web/models/product.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,12 +14,12 @@ const TableNameProduct = "product" // Product mapped from table type Product struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:产品ID" json:"id"` // 产品ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:产品ID" json:"id"` // 产品ID Code string `gorm:"column:code;not null;comment:产品代码" json:"code"` // 产品代码 Name string `gorm:"column:name;not null;comment:产品名称" json:"name"` // 产品名称 Description string `gorm:"column:description;comment:产品描述" json:"description"` // 产品描述 - Sort int32 `gorm:"column:sort;not null;comment:排序" json:"sort"` // 排序 - Status int32 `gorm:"column:status;not null;default:1;comment:产品状态:0-禁用,1-正常" json:"status"` // 产品状态:0-禁用,1-正常 + Sort int32 `gorm:"column:sort;not null;comment:排序" json:"sort"` // 排序 + Status int32 `gorm:"column:status;not null;default:1;comment:产品状态:0-禁用,1-正常" json:"status"` // 产品状态:0-禁用,1-正常 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/proxy.gen.go b/web/models/proxy.gen.go index ba429a0..a436790 100644 --- a/web/models/proxy.gen.go +++ b/web/models/proxy.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -15,11 +15,11 @@ const TableNameProxy = "proxy" // Proxy mapped from table type Proxy struct { ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:代理服务ID" json:"id"` // 代理服务ID - Version int32 `gorm:"column:version;not null;comment:代理服务版本" json:"version"` // 代理服务版本 - Name string `gorm:"column:name;not null;comment:代理服务名称" json:"name"` // 代理服务名称 - Host string `gorm:"column:host;not null;comment:代理服务地址" json:"host"` // 代理服务地址 - Type int32 `gorm:"column:type;not null;comment:代理服务类型:1-三方,2-自有" json:"type"` // 代理服务类型:1-三方,2-自有 - Secret string `gorm:"column:secret;comment:代理服务密钥" json:"secret"` // 代理服务密钥 + Version int32 `gorm:"column:version;not null;comment:代理服务版本" json:"version"` // 代理服务版本 + Name string `gorm:"column:name;not null;comment:代理服务名称" json:"name"` // 代理服务名称 + Host string `gorm:"column:host;not null;comment:代理服务地址" json:"host"` // 代理服务地址 + Type int32 `gorm:"column:type;not null;comment:代理服务类型:1-三方,2-自有" json:"type"` // 代理服务类型:1-三方,2-自有 + Secret string `gorm:"column:secret;comment:代理服务密钥" json:"secret"` // 代理服务密钥 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/refund.gen.go b/web/models/refund.gen.go index aee565c..3a00869 100644 --- a/web/models/refund.gen.go +++ b/web/models/refund.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,15 +14,15 @@ const TableNameRefund = "refund" // Refund mapped from table type Refund struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:退款ID" json:"id"` // 退款ID - TradeID int32 `gorm:"column:trade_id;not null;comment:订单ID" json:"trade_id"` // 订单ID - ProductID int32 `gorm:"column:product_id;comment:产品ID" json:"product_id"` // 产品ID - Amount float64 `gorm:"column:amount;not null;comment:退款金额" json:"amount"` // 退款金额 - Reason string `gorm:"column:reason;comment:退款原因" json:"reason"` // 退款原因 - Status int32 `gorm:"column:status;not null;comment:退款状态:0-待处理,1-已退款,2-已拒绝" json:"status"` // 退款状态:0-待处理,1-已退款,2-已拒绝 - CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 - UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:退款ID" json:"id"` // 退款ID + TradeID int32 `gorm:"column:trade_id;not null;comment:订单ID" json:"trade_id"` // 订单ID + ProductID int32 `gorm:"column:product_id;comment:产品ID" json:"product_id"` // 产品ID + Amount float64 `gorm:"column:amount;not null;comment:退款金额" json:"amount"` // 退款金额 + Reason string `gorm:"column:reason;comment:退款原因" json:"reason"` // 退款原因 + Status int32 `gorm:"column:status;not null;comment:退款状态:0-待处理,1-已退款,2-已拒绝" json:"status"` // 退款状态:0-待处理,1-已退款,2-已拒绝 + CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 + UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 } // TableName Refund's table name diff --git a/web/models/resource.gen.go b/web/models/resource.gen.go index c03a49d..2cce3e8 100644 --- a/web/models/resource.gen.go +++ b/web/models/resource.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,11 +14,11 @@ const TableNameResource = "resource" // Resource mapped from table type Resource struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:套餐ID" json:"id"` // 套餐ID - UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:套餐ID" json:"id"` // 套餐ID + UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID ResourceNo string `gorm:"column:resource_no;comment:套餐编号" json:"resource_no"` // 套餐编号 Active bool `gorm:"column:active;not null;default:true;comment:套餐状态" json:"active"` // 套餐状态 - Type int32 `gorm:"column:type;not null;comment:套餐类型:1-动态,2-隧道,3-独享" json:"type"` // 套餐类型:1-动态,2-隧道,3-独享 + Type int32 `gorm:"column:type;not null;comment:套餐类型:1-动态,2-隧道,3-独享" json:"type"` // 套餐类型:1-动态,2-隧道,3-独享 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/resource_psr.gen.go b/web/models/resource_psr.gen.go index 524582f..061453a 100644 --- a/web/models/resource_psr.gen.go +++ b/web/models/resource_psr.gen.go @@ -4,18 +4,20 @@ package models -import "platform/pkg/orm" +import ( + "platform/web/globals/orm" +) const TableNameResourcePsr = "resource_psr" // ResourcePsr mapped from table type ResourcePsr struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID - ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID - Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒) - Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数 - Expire orm.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间 - Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID + ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID + Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒) + Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数 + Expire orm.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间 + Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用 } // TableName ResourcePsr's table name diff --git a/web/models/resource_pss.gen.go b/web/models/resource_pss.gen.go index 70d28ac..8850de8 100644 --- a/web/models/resource_pss.gen.go +++ b/web/models/resource_pss.gen.go @@ -4,22 +4,24 @@ package models -import "platform/pkg/orm" +import ( + "platform/web/globals/orm" +) const TableNameResourcePss = "resource_pss" // ResourcePss mapped from table type ResourcePss struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID - ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID - Type int32 `gorm:"column:type;comment:套餐类型:1-包时,2-包量" json:"type"` // 套餐类型:1-包时,2-包量 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID + ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID + Type int32 `gorm:"column:type;comment:套餐类型:1-包时,2-包量" json:"type"` // 套餐类型:1-包时,2-包量 Live int32 `gorm:"column:live;comment:可用时长(秒)" json:"live"` // 可用时长(秒) - Expire orm.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间 - Quota int32 `gorm:"column:quota;comment:配额数量" json:"quota"` // 配额数量 - Used int32 `gorm:"column:used;not null;comment:已用数量" json:"used"` // 已用数量 - DailyLimit int32 `gorm:"column:daily_limit;not null;comment:每日限制" json:"daily_limit"` // 每日限制 - DailyUsed int32 `gorm:"column:daily_used;not null;comment:今日已用数量" json:"daily_used"` // 今日已用数量 - DailyLast orm.LocalDateTime `gorm:"column:daily_last;comment:今日最后使用时间" json:"daily_last"` // 今日最后使用时间 + Expire orm.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间 + Quota int32 `gorm:"column:quota;comment:配额数量" json:"quota"` // 配额数量 + Used int32 `gorm:"column:used;not null;comment:已用数量" json:"used"` // 已用数量 + DailyLimit int32 `gorm:"column:daily_limit;not null;comment:每日限制" json:"daily_limit"` // 每日限制 + DailyUsed int32 `gorm:"column:daily_used;not null;comment:今日已用数量" json:"daily_used"` // 今日已用数量 + DailyLast orm.LocalDateTime `gorm:"column:daily_last;comment:今日最后使用时间" json:"daily_last"` // 今日最后使用时间 } // TableName ResourcePss's table name diff --git a/web/models/trade.gen.go b/web/models/trade.gen.go index 6c95c7e..f5a7d70 100644 --- a/web/models/trade.gen.go +++ b/web/models/trade.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,23 +14,23 @@ const TableNameTrade = "trade" // Trade mapped from table type Trade struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:订单ID" json:"id"` // 订单ID - UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID - InnerNo string `gorm:"column:inner_no;not null;comment:内部订单号" json:"inner_no"` // 内部订单号 - OuterNo string `gorm:"column:outer_no;comment:外部订单号" json:"outer_no"` // 外部订单号 - Type int32 `gorm:"column:type;not null;comment:订单类型:1-购买产品,2-充值余额" json:"type"` // 订单类型:1-购买产品,2-充值余额 - Subject string `gorm:"column:subject;not null;comment:订单主题" json:"subject"` // 订单主题 - Remark string `gorm:"column:remark;comment:订单备注" json:"remark"` // 订单备注 - Amount float64 `gorm:"column:amount;not null;comment:订单总金额" json:"amount"` // 订单总金额 - Payment float64 `gorm:"column:payment;not null;comment:支付金额" json:"payment"` // 支付金额 - Method int32 `gorm:"column:method;not null;comment:支付方式:1-支付宝,2-微信" json:"method"` // 支付方式:1-支付宝,2-微信 - Status int32 `gorm:"column:status;not null;comment:订单状态:0-待支付,1-已支付,2-已取消,3-已退款" json:"status"` // 订单状态:0-待支付,1-已支付,2-已取消,3-已退款 - PayURL string `gorm:"column:pay_url;comment:支付链接" json:"pay_url"` // 支付链接 - PaidAt orm.LocalDateTime `gorm:"column:paid_at;comment:支付时间" json:"paid_at"` // 支付时间 - CancelAt orm.LocalDateTime `gorm:"column:cancel_at;comment:取消时间" json:"cancel_at"` // 取消时间 - CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 - UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:订单ID" json:"id"` // 订单ID + UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID + InnerNo string `gorm:"column:inner_no;not null;comment:内部订单号" json:"inner_no"` // 内部订单号 + OuterNo string `gorm:"column:outer_no;comment:外部订单号" json:"outer_no"` // 外部订单号 + Type int32 `gorm:"column:type;not null;comment:订单类型:1-购买产品,2-充值余额" json:"type"` // 订单类型:1-购买产品,2-充值余额 + Subject string `gorm:"column:subject;not null;comment:订单主题" json:"subject"` // 订单主题 + Remark string `gorm:"column:remark;comment:订单备注" json:"remark"` // 订单备注 + Amount float64 `gorm:"column:amount;not null;comment:订单总金额" json:"amount"` // 订单总金额 + Payment float64 `gorm:"column:payment;not null;comment:支付金额" json:"payment"` // 支付金额 + Method int32 `gorm:"column:method;not null;comment:支付方式:1-支付宝,2-微信" json:"method"` // 支付方式:1-支付宝,2-微信 + Status int32 `gorm:"column:status;not null;comment:订单状态:0-待支付,1-已支付,2-已取消,3-已退款" json:"status"` // 订单状态:0-待支付,1-已支付,2-已取消,3-已退款 + PayURL string `gorm:"column:pay_url;comment:支付链接" json:"pay_url"` // 支付链接 + PaidAt orm.LocalDateTime `gorm:"column:paid_at;comment:支付时间" json:"paid_at"` // 支付时间 + CancelAt orm.LocalDateTime `gorm:"column:cancel_at;comment:取消时间" json:"cancel_at"` // 取消时间 + CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 + UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 } // TableName Trade's table name diff --git a/web/models/user.gen.go b/web/models/user.gen.go index a4a294a..194a4bb 100644 --- a/web/models/user.gen.go +++ b/web/models/user.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -19,22 +19,22 @@ type User struct { Phone string `gorm:"column:phone;not null;comment:手机号码" json:"phone"` // 手机号码 Username string `gorm:"column:username;comment:用户名" json:"username"` // 用户名 Email string `gorm:"column:email" json:"email"` - Password string `gorm:"column:password;comment:用户密码" json:"password"` // 用户密码 - Name string `gorm:"column:name;comment:真实姓名" json:"name"` // 真实姓名 - Avatar string `gorm:"column:avatar;comment:头像URL" json:"avatar"` // 头像URL - Status int32 `gorm:"column:status;not null;default:1;comment:用户状态:0-禁用,1-正常" json:"status"` // 用户状态:0-禁用,1-正常 - Balance float64 `gorm:"column:balance;not null;comment:账户余额" json:"balance"` // 账户余额 - IDType int32 `gorm:"column:id_type;not null;comment:认证类型:0-未认证,1-个人认证,2-企业认证" json:"id_type"` // 认证类型:0-未认证,1-个人认证,2-企业认证 - IDNo string `gorm:"column:id_no;comment:身份证号或营业执照号" json:"id_no"` // 身份证号或营业执照号 - IDToken string `gorm:"column:id_token;comment:身份验证标识" json:"id_token"` // 身份验证标识 - ContactQQ string `gorm:"column:contact_qq;comment:QQ联系方式" json:"contact_qq"` // QQ联系方式 - ContactWechat string `gorm:"column:contact_wechat;comment:微信联系方式" json:"contact_wechat"` // 微信联系方式 - LastLogin orm.LocalDateTime `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间 - LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址 - LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理 - CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 - UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 + Password string `gorm:"column:password;comment:用户密码" json:"password"` // 用户密码 + Name string `gorm:"column:name;comment:真实姓名" json:"name"` // 真实姓名 + Avatar string `gorm:"column:avatar;comment:头像URL" json:"avatar"` // 头像URL + Status int32 `gorm:"column:status;not null;default:1;comment:用户状态:0-禁用,1-正常" json:"status"` // 用户状态:0-禁用,1-正常 + Balance float64 `gorm:"column:balance;not null;comment:账户余额" json:"balance"` // 账户余额 + IDType int32 `gorm:"column:id_type;not null;comment:认证类型:0-未认证,1-个人认证,2-企业认证" json:"id_type"` // 认证类型:0-未认证,1-个人认证,2-企业认证 + IDNo string `gorm:"column:id_no;comment:身份证号或营业执照号" json:"id_no"` // 身份证号或营业执照号 + IDToken string `gorm:"column:id_token;comment:身份验证标识" json:"id_token"` // 身份验证标识 + ContactQQ string `gorm:"column:contact_qq;comment:QQ联系方式" json:"contact_qq"` // QQ联系方式 + ContactWechat string `gorm:"column:contact_wechat;comment:微信联系方式" json:"contact_wechat"` // 微信联系方式 + LastLogin orm.LocalDateTime `gorm:"column:last_login;comment:最后登录时间" json:"last_login"` // 最后登录时间 + LastLoginHost string `gorm:"column:last_login_host;comment:最后登录地址" json:"last_login_host"` // 最后登录地址 + LastLoginAgent string `gorm:"column:last_login_agent;comment:最后登录代理" json:"last_login_agent"` // 最后登录代理 + CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 + UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 } // TableName User's table name diff --git a/web/models/user_role.gen.go b/web/models/user_role.gen.go index 678ad58..f788515 100644 --- a/web/models/user_role.gen.go +++ b/web/models/user_role.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,11 +14,11 @@ const TableNameUserRole = "user_role" // UserRole mapped from table type UserRole struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:角色ID" json:"id"` // 角色ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:角色ID" json:"id"` // 角色ID Name string `gorm:"column:name;not null;comment:角色名称" json:"name"` // 角色名称 Description string `gorm:"column:description;comment:角色描述" json:"description"` // 角色描述 Active bool `gorm:"column:active;default:true;comment:是否激活" json:"active"` // 是否激活 - Sort int32 `gorm:"column:sort;comment:排序" json:"sort"` // 排序 + Sort int32 `gorm:"column:sort;comment:排序" json:"sort"` // 排序 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/user_role_link.gen.go b/web/models/user_role_link.gen.go index 4ba0ac0..6069002 100644 --- a/web/models/user_role_link.gen.go +++ b/web/models/user_role_link.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,9 +14,9 @@ const TableNameUserRoleLink = "user_role_link" // UserRoleLink mapped from table type UserRoleLink struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID - UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID - RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID + UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID + RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/user_role_permission_link.gen.go b/web/models/user_role_permission_link.gen.go index 1f38952..91fcfd7 100644 --- a/web/models/user_role_permission_link.gen.go +++ b/web/models/user_role_permission_link.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,9 +14,9 @@ const TableNameUserRolePermissionLink = "user_role_permission_link" // UserRolePermissionLink mapped from table type UserRolePermissionLink struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID - RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID - PermissionID int32 `gorm:"column:permission_id;not null;comment:权限ID" json:"permission_id"` // 权限ID + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:关联ID" json:"id"` // 关联ID + RoleID int32 `gorm:"column:role_id;not null;comment:角色ID" json:"role_id"` // 角色ID + PermissionID int32 `gorm:"column:permission_id;not null;comment:权限ID" json:"permission_id"` // 权限ID CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/models/whitelist.gen.go b/web/models/whitelist.gen.go index e8735ed..27f80bf 100644 --- a/web/models/whitelist.gen.go +++ b/web/models/whitelist.gen.go @@ -5,7 +5,7 @@ package models import ( - "platform/pkg/orm" + "platform/web/globals/orm" "gorm.io/gorm" ) @@ -14,10 +14,10 @@ const TableNameWhitelist = "whitelist" // Whitelist mapped from table type Whitelist struct { - ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:白名单ID" json:"id"` // 白名单ID - UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID - Host string `gorm:"column:host;not null;comment:IP地址" json:"host"` // IP地址 - Remark string `gorm:"column:remark;comment:备注" json:"remark"` // 备注 + ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:白名单ID" json:"id"` // 白名单ID + UserID int32 `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"` // 用户ID + Host string `gorm:"column:host;not null;comment:IP地址" json:"host"` // IP地址 + Remark string `gorm:"column:remark;comment:备注" json:"remark"` // 备注 CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 diff --git a/web/services/auth.go b/web/services/auth.go index a29575d..f7d7b37 100644 --- a/web/services/auth.go +++ b/web/services/auth.go @@ -3,9 +3,9 @@ package services import ( "context" "errors" - "platform/pkg/orm" auth2 "platform/web/auth" client2 "platform/web/domains/client" + "platform/web/globals/orm" m "platform/web/models" q "platform/web/queries" "time" diff --git a/web/services/channel.go b/web/services/channel.go index 4be0f85..87f61b4 100644 --- a/web/services/channel.go +++ b/web/services/channel.go @@ -10,14 +10,13 @@ import ( "math" "math/rand/v2" "platform/pkg/env" - "platform/pkg/orm" - "platform/pkg/rds" "platform/pkg/u" "platform/web/auth" "platform/web/core" channel2 "platform/web/domains/channel" proxy2 "platform/web/domains/proxy" g "platform/web/globals" + "platform/web/globals/orm" m "platform/web/models" q "platform/web/queries" "strconv" @@ -652,7 +651,7 @@ func cache(ctx context.Context, channels []*m.Channel) error { return nil } - pipe := rds.Client.TxPipeline() + pipe := g.Redis.TxPipeline() zList := make([]redis.Z, 0, len(channels)) for _, channel := range channels { @@ -686,7 +685,7 @@ func deleteCache(ctx context.Context, channels []*m.Channel) error { for i := range channels { keys[i] = chKey(channels[i]) } - _, err := rds.Client.Del(ctx, keys...).Result() + _, err := g.Redis.Del(ctx, keys...).Result() if err != nil { return err } diff --git a/web/services/channel_test.go b/web/services/channel_test.go index 636a488..cb0a895 100644 --- a/web/services/channel_test.go +++ b/web/services/channel_test.go @@ -4,11 +4,11 @@ import ( "context" "encoding/json" "fmt" - "platform/pkg/orm" - "platform/pkg/testutil" "platform/web/auth" g "platform/web/globals" + "platform/web/globals/orm" "platform/web/models" + testutil2 "platform/web/testutil" "reflect" "strings" "testing" @@ -101,7 +101,7 @@ func Test_chKey(t *testing.T) { } func Test_cache(t *testing.T) { - mr := testutil.SetupRedisTest(t) + mr := testutil2.SetupRedisTest(t) type args struct { ctx context.Context @@ -202,7 +202,7 @@ func Test_cache(t *testing.T) { } func Test_deleteCache(t *testing.T) { - mr := testutil.SetupRedisTest(t) + mr := testutil2.SetupRedisTest(t) type args struct { ctx context.Context @@ -270,10 +270,10 @@ func Test_deleteCache(t *testing.T) { } func Test_channelService_CreateChannel(t *testing.T) { - mr := testutil.SetupRedisTest(t) - db := testutil.SetupDBTest(t) - mc := testutil.SetupCloudClientMock(t) - mg := testutil.SetupGatewayClientMock(t) + mr := testutil2.SetupRedisTest(t) + db := testutil2.SetupDBTest(t) + mc := testutil2.SetupCloudClientMock(t) + mg := testutil2.SetupGatewayClientMock(t) type args struct { ctx context.Context @@ -390,7 +390,7 @@ func Test_channelService_CreateChannel(t *testing.T) { return nil } - mg.PortConfigsMock = func(c *testutil.MockGatewayClient, params []g.PortConfigsReq) error { + mg.PortConfigsMock = func(c *testutil2.MockGatewayClient, params []g.PortConfigsReq) error { if c.Host != proxy.Host { return fmt.Errorf("代理主机不符合预期: %s", c.Host) } @@ -540,7 +540,7 @@ func Test_channelService_CreateChannel(t *testing.T) { return nil } - mg.PortConfigsMock = func(c *testutil.MockGatewayClient, params []g.PortConfigsReq) error { + mg.PortConfigsMock = func(c *testutil2.MockGatewayClient, params []g.PortConfigsReq) error { if c.Host != proxy.Host { return fmt.Errorf("代理主机不符合预期: %s", c.Host) } @@ -684,7 +684,7 @@ func Test_channelService_CreateChannel(t *testing.T) { return nil } - mg.PortConfigsMock = func(c *testutil.MockGatewayClient, params []g.PortConfigsReq) error { + mg.PortConfigsMock = func(c *testutil2.MockGatewayClient, params []g.PortConfigsReq) error { if c.Host != proxy.Host { return fmt.Errorf("代理主机不符合预期: %s", c.Host) } @@ -961,10 +961,10 @@ func Test_channelService_CreateChannel(t *testing.T) { } func Test_channelService_RemoveChannels(t *testing.T) { - mr := testutil.SetupRedisTest(t) - md := testutil.SetupDBTest(t) - mg := testutil.SetupGatewayClientMock(t) - mc := testutil.SetupCloudClientMock(t) + mr := testutil2.SetupRedisTest(t) + md := testutil2.SetupDBTest(t) + mg := testutil2.SetupGatewayClientMock(t) + mc := testutil2.SetupCloudClientMock(t) type args struct { ctx context.Context @@ -1055,7 +1055,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { } // 模拟网关客户端的响应 - mg.PortActiveMock = func(m *testutil.MockGatewayClient, param ...g.PortActiveReq) (map[string]g.PortData, error) { + mg.PortActiveMock = func(m *testutil2.MockGatewayClient, param ...g.PortActiveReq) (map[string]g.PortData, error) { switch { case m.Host == proxy.Host: return map[string]g.PortData{ @@ -1069,7 +1069,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { } return nil, fmt.Errorf("代理主机不符合预期: %s", m.Host) } - mg.PortConfigsMock = func(m *testutil.MockGatewayClient, params []g.PortConfigsReq) error { + mg.PortConfigsMock = func(m *testutil2.MockGatewayClient, params []g.PortConfigsReq) error { switch { case m.Host == proxy.Host: for _, param := range params { @@ -1104,7 +1104,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { switch { case param.Uuid == proxy.Name: var edges = []string{"edge1", "edge2", "edge4"} - if !testutil.SliceEqual(edges, param.Edge) { + if !testutil2.SliceEqual(edges, param.Edge) { return 0, fmt.Errorf("边缘节点不符合预期3: %v", param.Edge) } if len(param.Config) != 0 { @@ -1113,7 +1113,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { return len(param.Edge), nil case param.Uuid == proxy2.Name: var edges = []string{"edge3"} - if !testutil.SliceEqual(edges, param.Edge) { + if !testutil2.SliceEqual(edges, param.Edge) { return 0, fmt.Errorf("边缘节点不符合预期4: %v", param.Edge) } if len(param.Config) != 0 { @@ -1169,7 +1169,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { } // 模拟网关客户端的响应 - mg.PortActiveMock = func(m *testutil.MockGatewayClient, param ...g.PortActiveReq) (map[string]g.PortData, error) { + mg.PortActiveMock = func(m *testutil2.MockGatewayClient, param ...g.PortActiveReq) (map[string]g.PortData, error) { switch { case m.Host == proxy.Host: return map[string]g.PortData{ @@ -1183,7 +1183,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { } return nil, fmt.Errorf("代理主机不符合预期: %s", m.Host) } - mg.PortConfigsMock = func(m *testutil.MockGatewayClient, params []g.PortConfigsReq) error { + mg.PortConfigsMock = func(m *testutil2.MockGatewayClient, params []g.PortConfigsReq) error { switch { case m.Host == proxy.Host: for _, param := range params { @@ -1218,7 +1218,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { switch { case param.Uuid == proxy.Name: var edges = []string{"edge1", "edge2", "edge4"} - if !testutil.SliceEqual(edges, param.Edge) { + if !testutil2.SliceEqual(edges, param.Edge) { return 0, fmt.Errorf("边缘节点不符合预期7: %v", param.Edge) } if len(param.Config) != 0 { @@ -1227,7 +1227,7 @@ func Test_channelService_RemoveChannels(t *testing.T) { return len(param.Edge), nil case param.Uuid == proxy2.Name: var edges = []string{"edge3"} - if !testutil.SliceEqual(edges, param.Edge) { + if !testutil2.SliceEqual(edges, param.Edge) { return 0, fmt.Errorf("边缘节点不符合预期8: %v", param.Edge) } if len(param.Config) != 0 { diff --git a/web/services/id.go b/web/services/id.go index 5ba63da..ce05ac2 100644 --- a/web/services/id.go +++ b/web/services/id.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "platform/pkg/rds" + g "platform/web/globals" "strconv" "strings" "time" @@ -50,7 +50,7 @@ func (s *IdService) GenSerial(ctx context.Context) (string, error) { // 使用Redis事务确保原子操作 var sequence int64 - err := rds.Client.Watch(ctx, func(tx *redis.Tx) error { + err := g.Redis.Watch(ctx, func(tx *redis.Tx) error { // 获取当前序列号 currentVal, err := tx.Get(ctx, key).Int64() diff --git a/web/services/node.go b/web/services/node.go index 3501abe..93998b5 100644 --- a/web/services/node.go +++ b/web/services/node.go @@ -2,8 +2,8 @@ package services import ( "context" - "platform/pkg/orm" - "platform/web/models" + g "platform/web/globals" + m "platform/web/models" ) type NodeServiceErr string @@ -16,7 +16,7 @@ var Node = &nodeService{} type nodeService struct{} -func (s *nodeService) Filter(ctx context.Context, userId int32, count int, config ...NodeFilterConfig) ([]*models.Node, error) { +func (s *nodeService) Filter(ctx context.Context, userId int32, count int, config ...NodeFilterConfig) ([]*m.Node, error) { _config := NodeFilterConfig{} if len(config) > 0 { _config = config[0] @@ -26,7 +26,7 @@ func (s *nodeService) Filter(ctx context.Context, userId int32, count int, confi // 静态条件:省,市,运营商 // 排序方式,1.分配给该用户的次数 2.分配给全部用户的次数 3.todo 节点的健康状态 var nodes []*FilteredNode - orm.DB.Raw(filterSqlRaw, userId, _config.Isp, _config.Prov, _config.City). + g.DB.Raw(filterSqlRaw, userId, _config.Isp, _config.Prov, _config.City). Limit(count). Find(&nodes) diff --git a/web/services/resource.go b/web/services/resource.go index cfe4f5b..7678599 100644 --- a/web/services/resource.go +++ b/web/services/resource.go @@ -5,11 +5,11 @@ import ( "database/sql" "encoding/json" "fmt" - "platform/pkg/orm" - "platform/pkg/rds" bill2 "platform/web/domains/bill" resource2 "platform/web/domains/resource" trade2 "platform/web/domains/trade" + g "platform/web/globals" + "platform/web/globals/orm" m "platform/web/models" q "platform/web/queries" "strings" @@ -52,7 +52,7 @@ func (s *resourceService) PrepareResource(ctx context.Context, data *CreateResou if err != nil { return err } - err = rds.Client.Set(ctx, result.TradeNo, reqStr, 30*time.Minute).Err() + err = g.Redis.Set(ctx, result.TradeNo, reqStr, 30*time.Minute).Err() if err != nil { return err } @@ -69,7 +69,7 @@ func (s *resourceService) PrepareResource(ctx context.Context, data *CreateResou func (s *resourceService) CompleteResource(ctx context.Context, tradeNo string, rs *TransactionVerifyResult) error { // 获取请求缓存 - reqStr, err := rds.Client.Get(ctx, tradeNo).Result() + reqStr, err := g.Redis.Get(ctx, tradeNo).Result() if err != nil { return err } @@ -108,7 +108,7 @@ func (s *resourceService) CompleteResource(ctx context.Context, tradeNo string, } // 删除缓存 - err = rds.Client.Del(ctx, tradeNo).Err() + err = g.Redis.Del(ctx, tradeNo).Err() if err != nil { return err } @@ -265,7 +265,7 @@ func createResource(q *q.Query, data *CreateResourceData, uid int32) (*m.Resourc func (s *resourceService) CancelResource(ctx context.Context, tradeNo string, at time.Time, method trade2.Method) error { // 删除请求缓存 - _, err := rds.Client.Del(ctx, tradeNo).Result() + _, err := g.Redis.Del(ctx, tradeNo).Result() if err != nil { return err } diff --git a/web/services/session.go b/web/services/session.go index 8b7a816..b880287 100644 --- a/web/services/session.go +++ b/web/services/session.go @@ -6,8 +6,8 @@ import ( "errors" "fmt" "platform/pkg/env" - "platform/pkg/rds" "platform/web/auth" + g "platform/web/globals" "time" "github.com/google/uuid" @@ -45,7 +45,7 @@ type sessionService struct{} func (s *sessionService) Find(ctx context.Context, token string) (*auth.Context, error) { // 读取认证数据 - authJSON, err := rds.Client.Get(ctx, accessKey(token)).Result() + authJSON, err := g.Redis.Get(ctx, accessKey(token)).Result() if err != nil { if errors.Is(err, redis.Nil) { return nil, ErrInvalidToken @@ -89,7 +89,7 @@ func (s *sessionService) Create(ctx context.Context, authCtx auth.Context, remem var accessExpire = time.Duration(env.SessionAccessExpire) * time.Second var refreshExpire = time.Duration(env.SessionRefreshExpire) * time.Second - pipe := rds.Client.TxPipeline() + pipe := g.Redis.TxPipeline() pipe.Set(ctx, accessKey(accessToken), authData, accessExpire) if remember { pipe.Set(ctx, refreshKey(refreshToken), refreshData, refreshExpire) @@ -116,7 +116,7 @@ func (s *sessionService) Refresh(ctx context.Context, refreshToken string) (*Tok var tokenDetails *TokenDetails // 刷新令牌 - err := rds.Client.Watch(ctx, func(tx *redis.Tx) error { + err := g.Redis.Watch(ctx, func(tx *redis.Tx) error { // 先获取刷新令牌数据 refreshJson, err := tx.Get(ctx, rKey).Result() @@ -185,7 +185,7 @@ func (s *sessionService) Refresh(ctx context.Context, refreshToken string) (*Tok // Remove 删除会话 func (s *sessionService) Remove(ctx context.Context, accessToken, refreshToken string) error { - rds.Client.Del(ctx, accessKey(accessToken), refreshKey(refreshToken)) + g.Redis.Del(ctx, accessKey(accessToken), refreshKey(refreshToken)) return nil } diff --git a/web/services/session_test.go b/web/services/session_test.go index 31d4e11..3750604 100644 --- a/web/services/session_test.go +++ b/web/services/session_test.go @@ -3,8 +3,8 @@ package services import ( "context" "errors" - "platform/pkg/testutil" "platform/web/auth" + "platform/web/testutil" "reflect" "testing" "time" diff --git a/web/services/transaction.go b/web/services/transaction.go index 3a12b90..add7677 100644 --- a/web/services/transaction.go +++ b/web/services/transaction.go @@ -7,12 +7,12 @@ import ( "log/slog" "net/http" "platform/pkg/env" - "platform/pkg/orm" "platform/pkg/u" bill2 "platform/web/domains/bill" coupon2 "platform/web/domains/coupon" trade2 "platform/web/domains/trade" g "platform/web/globals" + "platform/web/globals/orm" m "platform/web/models" q "platform/web/queries" "strconv" diff --git a/web/services/verifier.go b/web/services/verifier.go index fc1898c..2839e41 100644 --- a/web/services/verifier.go +++ b/web/services/verifier.go @@ -8,7 +8,6 @@ import ( "log/slog" "math/rand" "platform/pkg/env" - "platform/pkg/rds" "platform/pkg/u" g "platform/web/globals" "strconv" @@ -50,7 +49,7 @@ func (s *verifierService) SendSms(ctx context.Context, phone string, purpose Ver keyLock := key + ":lock" // 检查发送频率,1 分钟内只能发送一次 - err := rds.Client.Watch(ctx, func(tx *redis.Tx) error { + err := g.Redis.Watch(ctx, func(tx *redis.Tx) error { result, err := tx.TTL(ctx, keyLock).Result() if err != nil { return err @@ -62,7 +61,7 @@ func (s *verifierService) SendSms(ctx context.Context, phone string, purpose Ver return VerifierServiceError("验证码检查异常") } - pipe := rds.Client.Pipeline() + pipe := g.Redis.Pipeline() pipe.Set(ctx, keyLock, "", 1*time.Minute) _, err = pipe.Exec(ctx) if err != nil { @@ -92,19 +91,19 @@ func (s *verifierService) SendSms(ctx context.Context, phone string, purpose Ver TemplateParam: u.P(string(params)), }) if err != nil { - _ = rds.Client.Del(ctx, key, keyLock).Err() + _ = g.Redis.Del(ctx, key, keyLock).Err() return err } if response.Body.Code == nil || *response.Body.Code != "OK" { - _ = rds.Client.Del(ctx, key, keyLock).Err() + _ = g.Redis.Del(ctx, key, keyLock).Err() return VerifierServiceError("验证码发送失败") } } // 设置验证码 - err = rds.Client.Set(ctx, key, code, 5*time.Minute).Err() + err = g.Redis.Set(ctx, key, code, 5*time.Minute).Err() if err != nil { - _ = rds.Client.Del(ctx, key, keyLock).Err() + _ = g.Redis.Del(ctx, key, keyLock).Err() return err } @@ -116,10 +115,10 @@ func (s *verifierService) VerifySms(ctx context.Context, phone, code string) err key := smsKey(phone, VerifierSmsPurposeLogin) keyLock := key + ":lock" - err := rds.Client.Watch(ctx, func(tx *redis.Tx) error { + err := g.Redis.Watch(ctx, func(tx *redis.Tx) error { // 检查验证码 - val, err := rds.Client.Get(ctx, key).Result() + val, err := g.Redis.Get(ctx, key).Result() if err != nil && !errors.Is(err, redis.Nil) { slog.Error("验证码获取失败", slog.Any("err", err)) return err diff --git a/web/services/verifier_test.go b/web/services/verifier_test.go index b03d129..123622c 100644 --- a/web/services/verifier_test.go +++ b/web/services/verifier_test.go @@ -3,7 +3,7 @@ package services import ( "context" "errors" - "platform/pkg/testutil" + "platform/web/testutil" "strconv" "testing" "time" diff --git a/pkg/testutil/db.go b/web/testutil/db.go similarity index 76% rename from pkg/testutil/db.go rename to web/testutil/db.go index 9623e3d..874b44f 100644 --- a/pkg/testutil/db.go +++ b/web/testutil/db.go @@ -1,8 +1,8 @@ package testutil import ( - "platform/pkg/orm" - "platform/web/models" + g"platform/web/globals" + m"platform/web/models" q "platform/web/queries" "testing" @@ -20,12 +20,12 @@ func SetupDBTest(t *testing.T) *gorm.DB { // 自动迁移数据表结构 err = gormDB.AutoMigrate( - &models.User{}, - &models.Whitelist{}, - &models.Resource{}, - &models.ResourcePss{}, - &models.Proxy{}, - &models.Channel{}, + &m.User{}, + &m.Whitelist{}, + &m.Resource{}, + &m.ResourcePss{}, + &m.Proxy{}, + &m.Channel{}, ) if err != nil { t.Fatalf("自动迁移表结构失败: %v", err) @@ -33,7 +33,7 @@ func SetupDBTest(t *testing.T) *gorm.DB { // 设置全局数据库连接 q.SetDefault(gormDB) - orm.DB = gormDB + g.DB = gormDB return gormDB } diff --git a/pkg/testutil/redis.go b/web/testutil/redis.go similarity index 89% rename from pkg/testutil/redis.go rename to web/testutil/redis.go index b7fccdc..9e9fd08 100644 --- a/pkg/testutil/redis.go +++ b/web/testutil/redis.go @@ -1,7 +1,7 @@ package testutil import ( - "platform/pkg/rds" + g "platform/web/globals" "testing" "github.com/alicebob/miniredis/v2" @@ -17,7 +17,7 @@ func SetupRedisTest(t *testing.T) *miniredis.Miniredis { } // 替换 Redis 客户端为测试客户端 - rds.Client = redis.NewClient(&redis.Options{ + g.Redis = redis.NewClient(&redis.Options{ Addr: mr.Addr(), }) diff --git a/pkg/testutil/remote.go b/web/testutil/remote.go similarity index 100% rename from pkg/testutil/remote.go rename to web/testutil/remote.go diff --git a/pkg/testutil/tools.go b/web/testutil/tools.go similarity index 100% rename from pkg/testutil/tools.go rename to web/testutil/tools.go diff --git a/web/web.go b/web/web.go index ff2963c..6370b1f 100644 --- a/web/web.go +++ b/web/web.go @@ -9,9 +9,9 @@ import ( "log/slog" "net/http" _ "net/http/pprof" - "platform/pkg/orm" "platform/web/auth" g "platform/web/globals" + "platform/web/globals/orm" m "platform/web/models" q "platform/web/queries" "runtime" @@ -45,12 +45,8 @@ func New(config *Config) (*Server, error) { func (s *Server) Run() error { // inits - g.InitBaiyin() - g.InitAlipay() - g.InitWechatPay() - g.InitAliyun() - g.InitValidator() - q.SetDefault(orm.DB) + g.Init() + q.SetDefault(g.DB) // config s.fiber = fiber.New(fiber.Config{ @@ -86,7 +82,17 @@ func (s *Server) Run() error { } func (s *Server) Stop() { - err := s.fiber.Shutdown() + err := g.ExitRedis() + if err != nil { + slog.Error("Failed to close Redis connection", slog.Any("err", err)) + } + + err = g.ExitOrm() + if err != nil { + slog.Error("Failed to close database connection", slog.Any("err", err)) + } + + err = s.fiber.Shutdown() if err != nil { slog.Error("Failed to shutdown server", slog.Any("err", err)) }