重构项目结构,将 orm 和 rds 包迁移到 web/globals
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
|
||||
### 长期
|
||||
|
||||
- 将 orm 和 rds 迁移到 web/globals 中
|
||||
- 分离项目脚手架(env,logs,Server 结构体)
|
||||
- 业务代码和测试代码共用的控制变量可以优化为环境变量
|
||||
- 考虑统计接口调用频率并通过接口展示
|
||||
- 考虑登录时曾经输入过验证码的用户,登录成功后允许一段时间内免输验证码
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
10
pkg/env/env.go
vendored
10
pkg/env/env.go
vendored
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
var Alipay *alipay.Client
|
||||
|
||||
func InitAlipay() {
|
||||
func initAlipay() {
|
||||
var client, err = alipay.New(
|
||||
env.AlipayAppId,
|
||||
env.AlipayAppPrivateKey,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
11
web/globals/init.go
Normal file
11
web/globals/init.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package globals
|
||||
|
||||
func Init() {
|
||||
initBaiyin()
|
||||
initAlipay()
|
||||
initWechatPay()
|
||||
initAliyun()
|
||||
initValidator()
|
||||
initRedis()
|
||||
initOrm()
|
||||
}
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
16
web/globals/orm/alias.go
Normal file
16
web/globals/orm/alias.go
Normal file
@@ -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())
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ type WechatPayClient struct {
|
||||
Notify *notify.Handler
|
||||
}
|
||||
|
||||
func InitWechatPay() {
|
||||
func initWechatPay() {
|
||||
|
||||
// 加载商户私钥
|
||||
private, err := base64.StdEncoding.DecodeString(env.WechatPayMchPrivateKey)
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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 <admin>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <admin_role>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <admin_role_link>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <admin_role_permission_link>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <announcement>
|
||||
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"` // 更新时间
|
||||
|
||||
@@ -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 <bill>
|
||||
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"` // 更新时间
|
||||
|
||||
@@ -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 <channel>
|
||||
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"` // 更新时间
|
||||
|
||||
@@ -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 <client>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <client_permission_link>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <coupon>
|
||||
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
|
||||
|
||||
@@ -4,23 +4,25 @@
|
||||
|
||||
package models
|
||||
|
||||
import "platform/pkg/orm"
|
||||
import (
|
||||
"platform/web/globals/orm"
|
||||
)
|
||||
|
||||
const TableNameLogsRequest = "logs_request"
|
||||
|
||||
// LogsRequest mapped from table <logs_request>
|
||||
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
|
||||
|
||||
@@ -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 <node>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <permission>
|
||||
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"` // 创建时间
|
||||
|
||||
@@ -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 <product>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <proxy>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <refund>
|
||||
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
|
||||
|
||||
@@ -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 <resource>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -4,18 +4,20 @@
|
||||
|
||||
package models
|
||||
|
||||
import "platform/pkg/orm"
|
||||
import (
|
||||
"platform/web/globals/orm"
|
||||
)
|
||||
|
||||
const TableNameResourcePsr = "resource_psr"
|
||||
|
||||
// ResourcePsr mapped from table <resource_psr>
|
||||
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
|
||||
|
||||
@@ -4,22 +4,24 @@
|
||||
|
||||
package models
|
||||
|
||||
import "platform/pkg/orm"
|
||||
import (
|
||||
"platform/web/globals/orm"
|
||||
)
|
||||
|
||||
const TableNameResourcePss = "resource_pss"
|
||||
|
||||
// ResourcePss mapped from table <resource_pss>
|
||||
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
|
||||
|
||||
@@ -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 <trade>
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <user_role>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <user_role_link>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <user_role_permission_link>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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 <whitelist>
|
||||
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"` // 删除时间
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"platform/pkg/testutil"
|
||||
"platform/web/auth"
|
||||
"platform/web/testutil"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"platform/pkg/testutil"
|
||||
"platform/web/testutil"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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(),
|
||||
})
|
||||
|
||||
22
web/web.go
22
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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user