优化数据库结构与数据插入逻辑

This commit is contained in:
2025-04-12 18:03:44 +08:00
parent 438a55cc3e
commit 8c268fd7a9
28 changed files with 218 additions and 213 deletions

View File

@@ -24,6 +24,8 @@
- [ ] Limiter - [ ] Limiter
- [ ] Compress - [ ] Compress
更新数据库填充
检查数据库枚举字段0 值只作为空值使用 检查数据库枚举字段0 值只作为空值使用
实现开发时迁移脚本: 实现开发时迁移脚本:
@@ -60,7 +62,7 @@ oauth token 验证授权范围
开发环境数据库迁移: 开发环境数据库迁移:
```powershell ```powershell
pg-schema-diff apply --schema-dir .\scripts\sql --dsn "host=localhost user=test password=test dbname=app port=5432 sslmode=disable TimeZone=Asia/Shanghai" pg-schema-diff apply --schema-dir .\scripts\sql --dsn "host=localhost user=test password=test dbname=app port=5432 sslmode=disable TimeZone=Asia/Shanghai" --allow-hazards INDEX_BUILD,INDEX_DROPPE
``` ```
## 枚举字典 ## 枚举字典

View File

@@ -2,9 +2,11 @@ package main
import ( import (
"log/slog" "log/slog"
"math"
"platform/pkg/env" "platform/pkg/env"
"platform/pkg/logs" "platform/pkg/logs"
"platform/pkg/orm" "platform/pkg/orm"
"platform/web/common"
m "platform/web/models" m "platform/web/models"
q "platform/web/queries" q "platform/web/queries"
"time" "time"
@@ -18,38 +20,28 @@ func main() {
orm.Init() orm.Init()
err := q.Q.Transaction(func(tx *q.Query) error { err := q.Q.Transaction(func(tx *q.Query) error {
q.User.
_ = q.User.
Select(q.User.Phone). Select(q.User.Phone).
Save(&m.User{ Create(&m.User{
Phone: "12312341234", Phone: "12312341234",
}) })
var user, _ = q.User.First() var user, _ = q.User.First()
q.Resource. _ = q.Resource.
Select(q.Resource.UserID, q.Resource.Active). Select(q.Resource.UserID, q.Resource.Active).
Create(&m.Resource{ Create(&m.Resource{
UserID: user.ID, UserID: user.ID,
Active: true, Active: true,
}) Pss: &m.ResourcePss{
var resource, _ = q.Resource.First() Live: 180,
Type: 1,
q.ResourcePss. Expire: common.LocalDateTime(time.Now().Add(24 * time.Hour * 1000)),
Select( DailyLimit: math.MaxInt32,
q.ResourcePss.ResourceID, },
q.ResourcePss.Live,
q.ResourcePss.Type,
q.ResourcePss.Expire,
q.ResourcePss.DailyLimit,
).
Create(&m.ResourcePss{
ResourceID: resource.ID,
Live: 180,
Type: 1,
Expire: time.Now().Add(24 * time.Hour * 1000),
DailyLimit: 300000,
}) })
q.Proxy. _ = q.Proxy.
Select(q.Proxy.Version, q.Proxy.Name, q.Proxy.Host, q.Proxy.Type, q.Proxy.Secret). Select(q.Proxy.Version, q.Proxy.Name, q.Proxy.Host, q.Proxy.Type, q.Proxy.Secret).
Create(&m.Proxy{ Create(&m.Proxy{
Version: 1, Version: 1,
@@ -59,7 +51,7 @@ func main() {
Secret: "api:123456", Secret: "api:123456",
}) })
q.Node. _ = q.Node.
Select( Select(
q.Node.Version, q.Node.Version,
q.Node.Name, q.Node.Name,
@@ -72,14 +64,14 @@ func main() {
Version: 1, Version: 1,
Name: "test-node", Name: "test-node",
Host: "123", Host: "123",
Isp: "test-isp", Isp: 0,
Prov: "test-prov", Prov: "test-prov",
City: "test-city", City: "test-city",
Status: 1}) Status: 1})
var testSecret, _ = bcrypt.GenerateFromPassword([]byte("test"), bcrypt.DefaultCost) var testSecret, _ = bcrypt.GenerateFromPassword([]byte("test"), bcrypt.DefaultCost)
var tasksSecret, _ = bcrypt.GenerateFromPassword([]byte("tasks"), bcrypt.DefaultCost) var tasksSecret, _ = bcrypt.GenerateFromPassword([]byte("tasks"), bcrypt.DefaultCost)
q.Client. _ = q.Client.
Select( Select(
q.Client.ClientID, q.Client.ClientID,
q.Client.ClientSecret, q.Client.ClientSecret,

View File

@@ -1,7 +1,10 @@
package main package main
import (
"fmt"
"time"
)
func main() { func main() {
println(rune('\r')) fmt.Printf("%v\n", time.Now())
println(rune('\n'))
println(rune('|'))
} }

13
pkg/u/u.go Normal file
View File

@@ -0,0 +1,13 @@
package u
import "time"
// P 是一个工具函数,用于在表达式内原地创建一个指针
func P[T any](v T) *T {
return &v
}
func Today() time.Time {
var now = time.Now()
return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
}

View File

@@ -1,6 +0,0 @@
package v
// P 是一个工具函数,用于在表达式内原地创建一个指针
func P[T any](v T) *T {
return &v
}

View File

@@ -424,15 +424,15 @@ comment on column proxy.deleted_at is '删除时间';
drop table if exists node cascade; drop table if exists node cascade;
create table node ( create table node (
id serial primary key, id serial primary key,
proxy_id int references proxy (id)
on update cascade
on delete cascade,
version int not null, version int not null,
name varchar(255) not null unique, name varchar(255) not null unique,
host varchar(255) not null, host varchar(255) not null,
isp int not null, isp int not null,
prov varchar(255) not null, prov varchar(255) not null,
city varchar(255) not null, city varchar(255) not null,
proxy_id int references proxy (id)
on update cascade
on delete cascade,
proxy_port int, proxy_port int,
status int not null default 0, status int not null default 0,
rtt int default 0, rtt int default 0,
@@ -458,7 +458,7 @@ comment on column node.prov is '省份';
comment on column node.city is '城市'; comment on column node.city is '城市';
comment on column node.proxy_id is '代理ID'; comment on column node.proxy_id is '代理ID';
comment on column node.proxy_port is '代理端口'; comment on column node.proxy_port is '代理端口';
comment on column node.status is '节点状态:1-正常,0-离线'; comment on column node.status is '节点状态0-离线1-正常';
comment on column node.rtt is '延迟'; comment on column node.rtt is '延迟';
comment on column node.loss is '丢包率'; comment on column node.loss is '丢包率';
comment on column node.created_at is '创建时间'; comment on column node.created_at is '创建时间';
@@ -593,6 +593,7 @@ create table resource (
on delete cascade, on delete cascade,
resource_no varchar(255) unique, resource_no varchar(255) unique,
active bool not null default true, active bool not null default true,
type int not null,
created_at timestamp default current_timestamp, created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp, updated_at timestamp default current_timestamp,
deleted_at timestamp deleted_at timestamp
@@ -600,6 +601,7 @@ create table resource (
create index resource_user_id_index on resource (user_id); create index resource_user_id_index on resource (user_id);
create index resource_resource_no_index on resource (resource_no); create index resource_resource_no_index on resource (resource_no);
create index resource_active_index on resource (active); create index resource_active_index on resource (active);
create index resource_type_index on resource (type);
create index resource_deleted_at_index on resource (deleted_at); create index resource_deleted_at_index on resource (deleted_at);
-- resource表字段注释 -- resource表字段注释
@@ -608,6 +610,7 @@ comment on column resource.id is '套餐ID';
comment on column resource.user_id is '用户ID'; comment on column resource.user_id is '用户ID';
comment on column resource.resource_no is '套餐编号'; comment on column resource.resource_no is '套餐编号';
comment on column resource.active is '套餐状态'; comment on column resource.active is '套餐状态';
comment on column resource.type is '套餐类型1-动态2-隧道3-独享';
comment on column resource.created_at is '创建时间'; comment on column resource.created_at is '创建时间';
comment on column resource.updated_at is '更新时间'; comment on column resource.updated_at is '更新时间';
comment on column resource.deleted_at is '删除时间'; comment on column resource.deleted_at is '删除时间';
@@ -626,13 +629,9 @@ create table resource_pss (
used int not null default 0, used int not null default 0,
daily_limit int not null default 0, daily_limit int not null default 0,
daily_used int not null default 0, daily_used int not null default 0,
daily_last timestamp, daily_last timestamp
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
); );
create index resource_pss_resource_id_index on resource_pss (resource_id); create index resource_pss_resource_id_index on resource_pss (resource_id);
create index resource_pss_deleted_at_index on resource_pss (deleted_at);
-- resource_pss表字段注释 -- resource_pss表字段注释
comment on table resource_pss is '动态代理套餐表'; comment on table resource_pss is '动态代理套餐表';
@@ -646,9 +645,6 @@ comment on column resource_pss.expire is '过期时间';
comment on column resource_pss.daily_limit is '每日限制'; comment on column resource_pss.daily_limit is '每日限制';
comment on column resource_pss.daily_used is '今日已用数量'; comment on column resource_pss.daily_used is '今日已用数量';
comment on column resource_pss.daily_last is '今日最后使用时间'; comment on column resource_pss.daily_last is '今日最后使用时间';
comment on column resource_pss.created_at is '创建时间';
comment on column resource_pss.updated_at is '更新时间';
comment on column resource_pss.deleted_at is '删除时间';
-- resource_psr -- resource_psr
drop table if exists resource_psr cascade; drop table if exists resource_psr cascade;
@@ -660,13 +656,9 @@ create table resource_psr (
live int, live int,
conn int, conn int,
expire timestamp, expire timestamp,
used bool, used bool
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
); );
create index resource_psr_resource_id_index on resource_psr (resource_id); create index resource_psr_resource_id_index on resource_psr (resource_id);
create index resource_psr_deleted_at_index on resource_psr (deleted_at);
-- resource_psr表字段注释 -- resource_psr表字段注释
comment on table resource_psr is '隧道代理套餐表'; comment on table resource_psr is '隧道代理套餐表';
@@ -676,9 +668,6 @@ comment on column resource_psr.live is '轮换周期(秒)';
comment on column resource_psr.conn is '最大连接数'; comment on column resource_psr.conn is '最大连接数';
comment on column resource_psr.expire is '过期时间'; comment on column resource_psr.expire is '过期时间';
comment on column resource_psr.used is '是否已使用'; comment on column resource_psr.used is '是否已使用';
comment on column resource_psr.created_at is '创建时间';
comment on column resource_psr.updated_at is '更新时间';
comment on column resource_psr.deleted_at is '删除时间';
-- resource_pps -- resource_pps
drop table if exists resource_pps cascade; drop table if exists resource_pps cascade;
@@ -686,21 +675,14 @@ create table resource_pps (
id serial primary key, id serial primary key,
resource_id int not null references resource (id) resource_id int not null references resource (id)
on update cascade on update cascade
on delete cascade, on delete cascade
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp,
deleted_at timestamp
); );
create index resource_pps_resource_id_index on resource_pps (resource_id); create index resource_pps_resource_id_index on resource_pps (resource_id);
create index resource_pps_deleted_at_index on resource_pps (deleted_at);
-- resource_pps表字段注释 -- resource_pps表字段注释
comment on table resource_pps is '独享代理套餐表'; comment on table resource_pps is '独享代理套餐表';
comment on column resource_pps.id is 'ID'; comment on column resource_pps.id is 'ID';
comment on column resource_pps.resource_id is '套餐ID'; comment on column resource_pps.resource_id is '套餐ID';
comment on column resource_pps.created_at is '创建时间';
comment on column resource_pps.updated_at is '更新时间';
comment on column resource_pps.deleted_at is '删除时间';
-- endregion -- endregion

View File

@@ -67,6 +67,7 @@ type PageResp struct {
type LocalDateTime time.Time type LocalDateTime time.Time
//goland:noinspection GoMixedReceiverTypes
func (ldt *LocalDateTime) Scan(value interface{}) (err error) { func (ldt *LocalDateTime) Scan(value interface{}) (err error) {
nullTime := &sql.NullTime{} nullTime := &sql.NullTime{}
@@ -85,27 +86,35 @@ func (ldt *LocalDateTime) Scan(value interface{}) (err error) {
return return
} }
//goland:noinspection GoMixedReceiverTypes
func (ldt LocalDateTime) Value() (driver.Value, error) { func (ldt LocalDateTime) Value() (driver.Value, error) {
return time.Time(ldt).In(time.Local), nil return time.Time(ldt).Local(), nil
} }
// GormDataType gorm common data type // GormDataType gorm common data type
//
//goland:noinspection GoMixedReceiverTy
//goland:noinspection GoMixedReceiverTypes
func (ldt LocalDateTime) GormDataType() string { func (ldt LocalDateTime) GormDataType() string {
return "ldt" return "ldt"
} }
//goland:noinspection GoMixedReceiverTypes
func (ldt LocalDateTime) GobEncode() ([]byte, error) { func (ldt LocalDateTime) GobEncode() ([]byte, error) {
return time.Time(ldt).GobEncode() return time.Time(ldt).GobEncode()
} }
//goland:noinspection GoMixedReceiverTypes
func (ldt *LocalDateTime) GobDecode(b []byte) error { func (ldt *LocalDateTime) GobDecode(b []byte) error {
return (*time.Time)(ldt).GobDecode(b) return (*time.Time)(ldt).GobDecode(b)
} }
//goland:noinspection GoMixedReceiverTypes
func (ldt LocalDateTime) MarshalJSON() ([]byte, error) { func (ldt LocalDateTime) MarshalJSON() ([]byte, error) {
return time.Time(ldt).MarshalJSON() return time.Time(ldt).MarshalJSON()
} }
//goland:noinspection GoMixedReceiverTypes
func (ldt *LocalDateTime) UnmarshalJSON(b []byte) error { func (ldt *LocalDateTime) UnmarshalJSON(b []byte) error {
return (*time.Time)(ldt).UnmarshalJSON(b) return (*time.Time)(ldt).UnmarshalJSON(b)
} }

View File

@@ -2,6 +2,7 @@ package handlers
import ( import (
"errors" "errors"
"platform/pkg/u"
"platform/web/auth" "platform/web/auth"
"platform/web/common" "platform/web/common"
m "platform/web/models" m "platform/web/models"
@@ -67,7 +68,7 @@ func ListResourcePss(c *fiber.Ctx) error {
var resource []*m.Resource var resource []*m.Resource
err = do.Debug(). err = do.Debug().
Order(q.ResourcePss.As(q.Resource.Pss.Name()).CreatedAt.Desc()). Order(q.Resource.CreatedAt.Desc()).
Offset(req.GetOffset()). Offset(req.GetOffset()).
Limit(req.GetLimit()). Limit(req.GetLimit()).
Scan(&resource) Scan(&resource)
@@ -95,6 +96,51 @@ func ListResourcePss(c *fiber.Ctx) error {
// endregion // endregion
// region AllResource
type AllResourceReq struct {
}
func AllResource(c *fiber.Ctx) error {
// 检查权限
authContext, err := auth.Protect(c, []services.PayloadType{services.PayloadUser}, []string{})
if err != nil {
return err
}
// 查询资源列表
pss := q.ResourcePss.As(q.Resource.Pss.Name())
do := q.Resource.Debug().
Joins(q.Resource.Pss).
Where(
q.Resource.UserID.Eq(authContext.Payload.Id),
q.Resource.Active.Is(true),
q.Resource.Where(
pss.Type.Eq(1),
pss.Expire.Gte(common.LocalDateTime(time.Now())),
).Or(
pss.Type.Eq(2),
pss.Quota.GtCol(pss.Used),
),
q.Resource.Where(
pss.DailyLast.Lt(common.LocalDateTime(u.Today())),
).Or(
pss.DailyUsed.LtCol(pss.DailyLimit),
),
)
resources, err := do.Debug().
Order(q.Resource.CreatedAt.Desc()).
Find()
if err != nil {
return err
}
return c.JSON(resources)
}
// endregion
// region CreateResourceByBalance // region CreateResourceByBalance
type CreateResourceByBalanceReq struct { type CreateResourceByBalanceReq struct {

View File

@@ -20,7 +20,6 @@ type Channel struct {
ProxyID int32 `gorm:"column:proxy_id;not null;comment:代理ID" json:"proxy_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 NodeID int32 `gorm:"column:node_id;comment:节点ID" json:"node_id"` // 节点ID
ProxyPort int32 `gorm:"column:proxy_port;not null;comment:转发端口" json:"proxy_port"` // 转发端口 ProxyPort int32 `gorm:"column:proxy_port;not null;comment:转发端口" json:"proxy_port"` // 转发端口
Protocol string `gorm:"column:protocol;comment:协议" json:"protocol"` // 协议
UserHost string `gorm:"column:user_host;comment:用户地址" json:"user_host"` // 用户地址 UserHost string `gorm:"column:user_host;comment:用户地址" json:"user_host"` // 用户地址
NodeHost string `gorm:"column:node_host;comment:节点地址" json:"node_host"` // 节点地址 NodeHost string `gorm:"column:node_host;comment:节点地址" json:"node_host"` // 节点地址
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认证
@@ -32,6 +31,7 @@ type Channel struct {
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
ProxyHost string `gorm:"column:proxy_host;not null" json:"proxy_host"` ProxyHost string `gorm:"column:proxy_host;not null" json:"proxy_host"`
Protocol int32 `gorm:"column:protocol" json:"protocol"`
} }
// TableName Channel's table name // TableName Channel's table name

View File

@@ -18,7 +18,6 @@ type Node struct {
Version int32 `gorm:"column:version;not null;comment:节点版本" json:"version"` // 节点版本 Version int32 `gorm:"column:version;not null;comment:节点版本" json:"version"` // 节点版本
Name string `gorm:"column:name;not null;comment:节点名称" json:"name"` // 节点名称 Name string `gorm:"column:name;not null;comment:节点名称" json:"name"` // 节点名称
Host string `gorm:"column:host;not null;comment:节点地址" json:"host"` // 节点地址 Host string `gorm:"column:host;not null;comment:节点地址" json:"host"` // 节点地址
Isp string `gorm:"column:isp;not null;comment:运营商" json:"isp"` // 运营商
Prov string `gorm:"column:prov;not null;comment:省份" json:"prov"` // 省份 Prov string `gorm:"column:prov;not null;comment:省份" json:"prov"` // 省份
City string `gorm:"column:city;not null;comment:城市" json:"city"` // 城市 City string `gorm:"column:city;not null;comment:城市" json:"city"` // 城市
ProxyID int32 `gorm:"column:proxy_id;comment:代理ID" json:"proxy_id"` // 代理ID ProxyID int32 `gorm:"column:proxy_id;comment:代理ID" json:"proxy_id"` // 代理ID
@@ -29,6 +28,7 @@ type Node struct {
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间 CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
Isp int32 `gorm:"column:isp;not null" json:"isp"`
} }
// TableName Node's table name // TableName Node's table name

View File

@@ -21,6 +21,8 @@ type Refund struct {
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
TradeID int32 `gorm:"column:trade_id;not null" json:"trade_id"` TradeID int32 `gorm:"column:trade_id;not null" json:"trade_id"`
Reason string `gorm:"column:reason" json:"reason"`
Status int32 `gorm:"column:status;not null" json:"status"`
} }
// TableName Refund's table name // TableName Refund's table name

View File

@@ -21,6 +21,7 @@ type Resource struct {
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间 UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
ResourceNo string `gorm:"column:resource_no" json:"resource_no"` ResourceNo string `gorm:"column:resource_no" json:"resource_no"`
Type int32 `gorm:"column:type;not null" json:"type"`
Pss *ResourcePss `gorm:"foreignKey:ResourceID;references:ID" json:"pss"` Pss *ResourcePss `gorm:"foreignKey:ResourceID;references:ID" json:"pss"`
} }

View File

@@ -4,21 +4,12 @@
package models package models
import (
"platform/web/common"
"gorm.io/gorm"
)
const TableNameResourcePps = "resource_pps" const TableNameResourcePps = "resource_pps"
// ResourcePps mapped from table <resource_pps> // ResourcePps mapped from table <resource_pps>
type ResourcePps struct { type ResourcePps 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
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
} }
// TableName ResourcePps's table name // TableName ResourcePps's table name

View File

@@ -5,25 +5,19 @@
package models package models
import ( import (
"platform/web/common"
"time" "time"
"gorm.io/gorm"
) )
const TableNameResourcePsr = "resource_psr" const TableNameResourcePsr = "resource_psr"
// ResourcePsr mapped from table <resource_psr> // ResourcePsr mapped from table <resource_psr>
type ResourcePsr struct { type ResourcePsr 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
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒) Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒)
Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数 Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数
Expire time.Time `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间 Expire time.Time `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间
Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用 Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
} }
// TableName ResourcePsr's table name // TableName ResourcePsr's table name

View File

@@ -4,29 +4,22 @@
package models package models
import ( import "platform/web/common"
"platform/web/common"
"gorm.io/gorm"
)
const TableNameResourcePss = "resource_pss" const TableNameResourcePss = "resource_pss"
// ResourcePss mapped from table <resource_pss> // ResourcePss mapped from table <resource_pss>
type ResourcePss struct { type ResourcePss 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
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_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-包量 Type int32 `gorm:"column:type;comment:套餐类型1-包时2-包量" json:"type"` // 套餐类型1-包时2-包量
Live int32 `gorm:"column:live;comment:可用时长(秒)" json:"live"` // 可用时长(秒) Live int32 `gorm:"column:live;comment:可用时长(秒)" json:"live"` // 可用时长(秒)
Quota int32 `gorm:"column:quota;comment:配额数量" json:"quota"` // 配额数量 Quota int32 `gorm:"column:quota;comment:配额数量" json:"quota"` // 配额数量
Expire common.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间 Expire common.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间
Used int32 `gorm:"column:used;not null;comment:已用数量" json:"used"` // 已用数量 Used int32 `gorm:"column:used;not null;comment:已用数量" json:"used"` // 已用数量
DailyLimit int32 `gorm:"column:daily_limit;not null;comment:每日限制" json:"daily_limit"` // 每日限制 DailyLimit int32 `gorm:"column:daily_limit;not null;comment:每日限制" json:"daily_limit"` // 每日限制
DailyUsed int32 `gorm:"column:daily_used;not null;comment:今日已用数量" json:"daily_used"` // 今日已用数量 DailyUsed int32 `gorm:"column:daily_used;not null;comment:今日已用数量" json:"daily_used"` // 今日已用数量
DailyLast common.LocalDateTime `gorm:"column:daily_last;comment:今日最后使用时间" json:"daily_last"` // 今日最后使用时间 DailyLast common.LocalDateTime `gorm:"column:daily_last;comment:今日最后使用时间" json:"daily_last"` // 今日最后使用时间
CreatedAt common.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
UpdatedAt common.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
} }
// TableName ResourcePss's table name // TableName ResourcePss's table name

View File

@@ -32,7 +32,6 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
_channel.ProxyID = field.NewInt32(tableName, "proxy_id") _channel.ProxyID = field.NewInt32(tableName, "proxy_id")
_channel.NodeID = field.NewInt32(tableName, "node_id") _channel.NodeID = field.NewInt32(tableName, "node_id")
_channel.ProxyPort = field.NewInt32(tableName, "proxy_port") _channel.ProxyPort = field.NewInt32(tableName, "proxy_port")
_channel.Protocol = field.NewString(tableName, "protocol")
_channel.UserHost = field.NewString(tableName, "user_host") _channel.UserHost = field.NewString(tableName, "user_host")
_channel.NodeHost = field.NewString(tableName, "node_host") _channel.NodeHost = field.NewString(tableName, "node_host")
_channel.AuthIP = field.NewBool(tableName, "auth_ip") _channel.AuthIP = field.NewBool(tableName, "auth_ip")
@@ -44,6 +43,7 @@ func newChannel(db *gorm.DB, opts ...gen.DOOption) channel {
_channel.UpdatedAt = field.NewField(tableName, "updated_at") _channel.UpdatedAt = field.NewField(tableName, "updated_at")
_channel.DeletedAt = field.NewField(tableName, "deleted_at") _channel.DeletedAt = field.NewField(tableName, "deleted_at")
_channel.ProxyHost = field.NewString(tableName, "proxy_host") _channel.ProxyHost = field.NewString(tableName, "proxy_host")
_channel.Protocol = field.NewInt32(tableName, "protocol")
_channel.fillFieldMap() _channel.fillFieldMap()
@@ -59,7 +59,6 @@ type channel struct {
ProxyID field.Int32 // 代理ID ProxyID field.Int32 // 代理ID
NodeID field.Int32 // 节点ID NodeID field.Int32 // 节点ID
ProxyPort field.Int32 // 转发端口 ProxyPort field.Int32 // 转发端口
Protocol field.String // 协议
UserHost field.String // 用户地址 UserHost field.String // 用户地址
NodeHost field.String // 节点地址 NodeHost field.String // 节点地址
AuthIP field.Bool // IP认证 AuthIP field.Bool // IP认证
@@ -71,6 +70,7 @@ type channel struct {
UpdatedAt field.Field // 更新时间 UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间 DeletedAt field.Field // 删除时间
ProxyHost field.String ProxyHost field.String
Protocol field.Int32
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
} }
@@ -92,7 +92,6 @@ func (c *channel) updateTableName(table string) *channel {
c.ProxyID = field.NewInt32(table, "proxy_id") c.ProxyID = field.NewInt32(table, "proxy_id")
c.NodeID = field.NewInt32(table, "node_id") c.NodeID = field.NewInt32(table, "node_id")
c.ProxyPort = field.NewInt32(table, "proxy_port") c.ProxyPort = field.NewInt32(table, "proxy_port")
c.Protocol = field.NewString(table, "protocol")
c.UserHost = field.NewString(table, "user_host") c.UserHost = field.NewString(table, "user_host")
c.NodeHost = field.NewString(table, "node_host") c.NodeHost = field.NewString(table, "node_host")
c.AuthIP = field.NewBool(table, "auth_ip") c.AuthIP = field.NewBool(table, "auth_ip")
@@ -104,6 +103,7 @@ func (c *channel) updateTableName(table string) *channel {
c.UpdatedAt = field.NewField(table, "updated_at") c.UpdatedAt = field.NewField(table, "updated_at")
c.DeletedAt = field.NewField(table, "deleted_at") c.DeletedAt = field.NewField(table, "deleted_at")
c.ProxyHost = field.NewString(table, "proxy_host") c.ProxyHost = field.NewString(table, "proxy_host")
c.Protocol = field.NewInt32(table, "protocol")
c.fillFieldMap() c.fillFieldMap()
@@ -126,7 +126,6 @@ func (c *channel) fillFieldMap() {
c.fieldMap["proxy_id"] = c.ProxyID c.fieldMap["proxy_id"] = c.ProxyID
c.fieldMap["node_id"] = c.NodeID c.fieldMap["node_id"] = c.NodeID
c.fieldMap["proxy_port"] = c.ProxyPort c.fieldMap["proxy_port"] = c.ProxyPort
c.fieldMap["protocol"] = c.Protocol
c.fieldMap["user_host"] = c.UserHost c.fieldMap["user_host"] = c.UserHost
c.fieldMap["node_host"] = c.NodeHost c.fieldMap["node_host"] = c.NodeHost
c.fieldMap["auth_ip"] = c.AuthIP c.fieldMap["auth_ip"] = c.AuthIP
@@ -138,6 +137,7 @@ func (c *channel) fillFieldMap() {
c.fieldMap["updated_at"] = c.UpdatedAt c.fieldMap["updated_at"] = c.UpdatedAt
c.fieldMap["deleted_at"] = c.DeletedAt c.fieldMap["deleted_at"] = c.DeletedAt
c.fieldMap["proxy_host"] = c.ProxyHost c.fieldMap["proxy_host"] = c.ProxyHost
c.fieldMap["protocol"] = c.Protocol
} }
func (c channel) clone(db *gorm.DB) channel { func (c channel) clone(db *gorm.DB) channel {

View File

@@ -31,7 +31,6 @@ func newNode(db *gorm.DB, opts ...gen.DOOption) node {
_node.Version = field.NewInt32(tableName, "version") _node.Version = field.NewInt32(tableName, "version")
_node.Name = field.NewString(tableName, "name") _node.Name = field.NewString(tableName, "name")
_node.Host = field.NewString(tableName, "host") _node.Host = field.NewString(tableName, "host")
_node.Isp = field.NewString(tableName, "isp")
_node.Prov = field.NewString(tableName, "prov") _node.Prov = field.NewString(tableName, "prov")
_node.City = field.NewString(tableName, "city") _node.City = field.NewString(tableName, "city")
_node.ProxyID = field.NewInt32(tableName, "proxy_id") _node.ProxyID = field.NewInt32(tableName, "proxy_id")
@@ -42,6 +41,7 @@ func newNode(db *gorm.DB, opts ...gen.DOOption) node {
_node.CreatedAt = field.NewField(tableName, "created_at") _node.CreatedAt = field.NewField(tableName, "created_at")
_node.UpdatedAt = field.NewField(tableName, "updated_at") _node.UpdatedAt = field.NewField(tableName, "updated_at")
_node.DeletedAt = field.NewField(tableName, "deleted_at") _node.DeletedAt = field.NewField(tableName, "deleted_at")
_node.Isp = field.NewInt32(tableName, "isp")
_node.fillFieldMap() _node.fillFieldMap()
@@ -56,7 +56,6 @@ type node struct {
Version field.Int32 // 节点版本 Version field.Int32 // 节点版本
Name field.String // 节点名称 Name field.String // 节点名称
Host field.String // 节点地址 Host field.String // 节点地址
Isp field.String // 运营商
Prov field.String // 省份 Prov field.String // 省份
City field.String // 城市 City field.String // 城市
ProxyID field.Int32 // 代理ID ProxyID field.Int32 // 代理ID
@@ -67,6 +66,7 @@ type node struct {
CreatedAt field.Field // 创建时间 CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间 UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间 DeletedAt field.Field // 删除时间
Isp field.Int32
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
} }
@@ -87,7 +87,6 @@ func (n *node) updateTableName(table string) *node {
n.Version = field.NewInt32(table, "version") n.Version = field.NewInt32(table, "version")
n.Name = field.NewString(table, "name") n.Name = field.NewString(table, "name")
n.Host = field.NewString(table, "host") n.Host = field.NewString(table, "host")
n.Isp = field.NewString(table, "isp")
n.Prov = field.NewString(table, "prov") n.Prov = field.NewString(table, "prov")
n.City = field.NewString(table, "city") n.City = field.NewString(table, "city")
n.ProxyID = field.NewInt32(table, "proxy_id") n.ProxyID = field.NewInt32(table, "proxy_id")
@@ -98,6 +97,7 @@ func (n *node) updateTableName(table string) *node {
n.CreatedAt = field.NewField(table, "created_at") n.CreatedAt = field.NewField(table, "created_at")
n.UpdatedAt = field.NewField(table, "updated_at") n.UpdatedAt = field.NewField(table, "updated_at")
n.DeletedAt = field.NewField(table, "deleted_at") n.DeletedAt = field.NewField(table, "deleted_at")
n.Isp = field.NewInt32(table, "isp")
n.fillFieldMap() n.fillFieldMap()
@@ -119,7 +119,6 @@ func (n *node) fillFieldMap() {
n.fieldMap["version"] = n.Version n.fieldMap["version"] = n.Version
n.fieldMap["name"] = n.Name n.fieldMap["name"] = n.Name
n.fieldMap["host"] = n.Host n.fieldMap["host"] = n.Host
n.fieldMap["isp"] = n.Isp
n.fieldMap["prov"] = n.Prov n.fieldMap["prov"] = n.Prov
n.fieldMap["city"] = n.City n.fieldMap["city"] = n.City
n.fieldMap["proxy_id"] = n.ProxyID n.fieldMap["proxy_id"] = n.ProxyID
@@ -130,6 +129,7 @@ func (n *node) fillFieldMap() {
n.fieldMap["created_at"] = n.CreatedAt n.fieldMap["created_at"] = n.CreatedAt
n.fieldMap["updated_at"] = n.UpdatedAt n.fieldMap["updated_at"] = n.UpdatedAt
n.fieldMap["deleted_at"] = n.DeletedAt n.fieldMap["deleted_at"] = n.DeletedAt
n.fieldMap["isp"] = n.Isp
} }
func (n node) clone(db *gorm.DB) node { func (n node) clone(db *gorm.DB) node {

View File

@@ -34,6 +34,8 @@ func newRefund(db *gorm.DB, opts ...gen.DOOption) refund {
_refund.UpdatedAt = field.NewField(tableName, "updated_at") _refund.UpdatedAt = field.NewField(tableName, "updated_at")
_refund.DeletedAt = field.NewField(tableName, "deleted_at") _refund.DeletedAt = field.NewField(tableName, "deleted_at")
_refund.TradeID = field.NewInt32(tableName, "trade_id") _refund.TradeID = field.NewInt32(tableName, "trade_id")
_refund.Reason = field.NewString(tableName, "reason")
_refund.Status = field.NewInt32(tableName, "status")
_refund.fillFieldMap() _refund.fillFieldMap()
@@ -51,6 +53,8 @@ type refund struct {
UpdatedAt field.Field // 更新时间 UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间 DeletedAt field.Field // 删除时间
TradeID field.Int32 TradeID field.Int32
Reason field.String
Status field.Int32
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
} }
@@ -74,6 +78,8 @@ func (r *refund) updateTableName(table string) *refund {
r.UpdatedAt = field.NewField(table, "updated_at") r.UpdatedAt = field.NewField(table, "updated_at")
r.DeletedAt = field.NewField(table, "deleted_at") r.DeletedAt = field.NewField(table, "deleted_at")
r.TradeID = field.NewInt32(table, "trade_id") r.TradeID = field.NewInt32(table, "trade_id")
r.Reason = field.NewString(table, "reason")
r.Status = field.NewInt32(table, "status")
r.fillFieldMap() r.fillFieldMap()
@@ -90,7 +96,7 @@ func (r *refund) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
} }
func (r *refund) fillFieldMap() { func (r *refund) fillFieldMap() {
r.fieldMap = make(map[string]field.Expr, 7) r.fieldMap = make(map[string]field.Expr, 9)
r.fieldMap["id"] = r.ID r.fieldMap["id"] = r.ID
r.fieldMap["product_id"] = r.ProductID r.fieldMap["product_id"] = r.ProductID
r.fieldMap["amount"] = r.Amount r.fieldMap["amount"] = r.Amount
@@ -98,6 +104,8 @@ func (r *refund) fillFieldMap() {
r.fieldMap["updated_at"] = r.UpdatedAt r.fieldMap["updated_at"] = r.UpdatedAt
r.fieldMap["deleted_at"] = r.DeletedAt r.fieldMap["deleted_at"] = r.DeletedAt
r.fieldMap["trade_id"] = r.TradeID r.fieldMap["trade_id"] = r.TradeID
r.fieldMap["reason"] = r.Reason
r.fieldMap["status"] = r.Status
} }
func (r refund) clone(db *gorm.DB) refund { func (r refund) clone(db *gorm.DB) refund {

View File

@@ -34,6 +34,7 @@ func newResource(db *gorm.DB, opts ...gen.DOOption) resource {
_resource.UpdatedAt = field.NewField(tableName, "updated_at") _resource.UpdatedAt = field.NewField(tableName, "updated_at")
_resource.DeletedAt = field.NewField(tableName, "deleted_at") _resource.DeletedAt = field.NewField(tableName, "deleted_at")
_resource.ResourceNo = field.NewString(tableName, "resource_no") _resource.ResourceNo = field.NewString(tableName, "resource_no")
_resource.Type = field.NewInt32(tableName, "type")
_resource.Pss = resourceHasOnePss{ _resource.Pss = resourceHasOnePss{
db: db.Session(&gorm.Session{}), db: db.Session(&gorm.Session{}),
@@ -56,6 +57,7 @@ type resource struct {
UpdatedAt field.Field // 更新时间 UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间 DeletedAt field.Field // 删除时间
ResourceNo field.String ResourceNo field.String
Type field.Int32
Pss resourceHasOnePss Pss resourceHasOnePss
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
@@ -80,6 +82,7 @@ func (r *resource) updateTableName(table string) *resource {
r.UpdatedAt = field.NewField(table, "updated_at") r.UpdatedAt = field.NewField(table, "updated_at")
r.DeletedAt = field.NewField(table, "deleted_at") r.DeletedAt = field.NewField(table, "deleted_at")
r.ResourceNo = field.NewString(table, "resource_no") r.ResourceNo = field.NewString(table, "resource_no")
r.Type = field.NewInt32(table, "type")
r.fillFieldMap() r.fillFieldMap()
@@ -96,7 +99,7 @@ func (r *resource) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
} }
func (r *resource) fillFieldMap() { func (r *resource) fillFieldMap() {
r.fieldMap = make(map[string]field.Expr, 8) r.fieldMap = make(map[string]field.Expr, 9)
r.fieldMap["id"] = r.ID r.fieldMap["id"] = r.ID
r.fieldMap["user_id"] = r.UserID r.fieldMap["user_id"] = r.UserID
r.fieldMap["active"] = r.Active r.fieldMap["active"] = r.Active
@@ -104,6 +107,7 @@ func (r *resource) fillFieldMap() {
r.fieldMap["updated_at"] = r.UpdatedAt r.fieldMap["updated_at"] = r.UpdatedAt
r.fieldMap["deleted_at"] = r.DeletedAt r.fieldMap["deleted_at"] = r.DeletedAt
r.fieldMap["resource_no"] = r.ResourceNo r.fieldMap["resource_no"] = r.ResourceNo
r.fieldMap["type"] = r.Type
} }

View File

@@ -29,9 +29,6 @@ func newResourcePps(db *gorm.DB, opts ...gen.DOOption) resourcePps {
_resourcePps.ALL = field.NewAsterisk(tableName) _resourcePps.ALL = field.NewAsterisk(tableName)
_resourcePps.ID = field.NewInt32(tableName, "id") _resourcePps.ID = field.NewInt32(tableName, "id")
_resourcePps.ResourceID = field.NewInt32(tableName, "resource_id") _resourcePps.ResourceID = field.NewInt32(tableName, "resource_id")
_resourcePps.CreatedAt = field.NewField(tableName, "created_at")
_resourcePps.UpdatedAt = field.NewField(tableName, "updated_at")
_resourcePps.DeletedAt = field.NewField(tableName, "deleted_at")
_resourcePps.fillFieldMap() _resourcePps.fillFieldMap()
@@ -44,9 +41,6 @@ type resourcePps struct {
ALL field.Asterisk ALL field.Asterisk
ID field.Int32 // ID ID field.Int32 // ID
ResourceID field.Int32 // 套餐ID ResourceID field.Int32 // 套餐ID
CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
} }
@@ -65,9 +59,6 @@ func (r *resourcePps) updateTableName(table string) *resourcePps {
r.ALL = field.NewAsterisk(table) r.ALL = field.NewAsterisk(table)
r.ID = field.NewInt32(table, "id") r.ID = field.NewInt32(table, "id")
r.ResourceID = field.NewInt32(table, "resource_id") r.ResourceID = field.NewInt32(table, "resource_id")
r.CreatedAt = field.NewField(table, "created_at")
r.UpdatedAt = field.NewField(table, "updated_at")
r.DeletedAt = field.NewField(table, "deleted_at")
r.fillFieldMap() r.fillFieldMap()
@@ -84,12 +75,9 @@ func (r *resourcePps) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
} }
func (r *resourcePps) fillFieldMap() { func (r *resourcePps) fillFieldMap() {
r.fieldMap = make(map[string]field.Expr, 5) r.fieldMap = make(map[string]field.Expr, 2)
r.fieldMap["id"] = r.ID r.fieldMap["id"] = r.ID
r.fieldMap["resource_id"] = r.ResourceID r.fieldMap["resource_id"] = r.ResourceID
r.fieldMap["created_at"] = r.CreatedAt
r.fieldMap["updated_at"] = r.UpdatedAt
r.fieldMap["deleted_at"] = r.DeletedAt
} }
func (r resourcePps) clone(db *gorm.DB) resourcePps { func (r resourcePps) clone(db *gorm.DB) resourcePps {

View File

@@ -33,9 +33,6 @@ func newResourcePsr(db *gorm.DB, opts ...gen.DOOption) resourcePsr {
_resourcePsr.Conn = field.NewInt32(tableName, "conn") _resourcePsr.Conn = field.NewInt32(tableName, "conn")
_resourcePsr.Expire = field.NewTime(tableName, "expire") _resourcePsr.Expire = field.NewTime(tableName, "expire")
_resourcePsr.Used = field.NewBool(tableName, "used") _resourcePsr.Used = field.NewBool(tableName, "used")
_resourcePsr.CreatedAt = field.NewField(tableName, "created_at")
_resourcePsr.UpdatedAt = field.NewField(tableName, "updated_at")
_resourcePsr.DeletedAt = field.NewField(tableName, "deleted_at")
_resourcePsr.fillFieldMap() _resourcePsr.fillFieldMap()
@@ -52,9 +49,6 @@ type resourcePsr struct {
Conn field.Int32 // 最大连接数 Conn field.Int32 // 最大连接数
Expire field.Time // 过期时间 Expire field.Time // 过期时间
Used field.Bool // 是否已使用 Used field.Bool // 是否已使用
CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
} }
@@ -77,9 +71,6 @@ func (r *resourcePsr) updateTableName(table string) *resourcePsr {
r.Conn = field.NewInt32(table, "conn") r.Conn = field.NewInt32(table, "conn")
r.Expire = field.NewTime(table, "expire") r.Expire = field.NewTime(table, "expire")
r.Used = field.NewBool(table, "used") r.Used = field.NewBool(table, "used")
r.CreatedAt = field.NewField(table, "created_at")
r.UpdatedAt = field.NewField(table, "updated_at")
r.DeletedAt = field.NewField(table, "deleted_at")
r.fillFieldMap() r.fillFieldMap()
@@ -96,16 +87,13 @@ func (r *resourcePsr) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
} }
func (r *resourcePsr) fillFieldMap() { func (r *resourcePsr) fillFieldMap() {
r.fieldMap = make(map[string]field.Expr, 9) r.fieldMap = make(map[string]field.Expr, 6)
r.fieldMap["id"] = r.ID r.fieldMap["id"] = r.ID
r.fieldMap["resource_id"] = r.ResourceID r.fieldMap["resource_id"] = r.ResourceID
r.fieldMap["live"] = r.Live r.fieldMap["live"] = r.Live
r.fieldMap["conn"] = r.Conn r.fieldMap["conn"] = r.Conn
r.fieldMap["expire"] = r.Expire r.fieldMap["expire"] = r.Expire
r.fieldMap["used"] = r.Used r.fieldMap["used"] = r.Used
r.fieldMap["created_at"] = r.CreatedAt
r.fieldMap["updated_at"] = r.UpdatedAt
r.fieldMap["deleted_at"] = r.DeletedAt
} }
func (r resourcePsr) clone(db *gorm.DB) resourcePsr { func (r resourcePsr) clone(db *gorm.DB) resourcePsr {

View File

@@ -37,9 +37,6 @@ func newResourcePss(db *gorm.DB, opts ...gen.DOOption) resourcePss {
_resourcePss.DailyLimit = field.NewInt32(tableName, "daily_limit") _resourcePss.DailyLimit = field.NewInt32(tableName, "daily_limit")
_resourcePss.DailyUsed = field.NewInt32(tableName, "daily_used") _resourcePss.DailyUsed = field.NewInt32(tableName, "daily_used")
_resourcePss.DailyLast = field.NewField(tableName, "daily_last") _resourcePss.DailyLast = field.NewField(tableName, "daily_last")
_resourcePss.CreatedAt = field.NewField(tableName, "created_at")
_resourcePss.UpdatedAt = field.NewField(tableName, "updated_at")
_resourcePss.DeletedAt = field.NewField(tableName, "deleted_at")
_resourcePss.fillFieldMap() _resourcePss.fillFieldMap()
@@ -60,9 +57,6 @@ type resourcePss struct {
DailyLimit field.Int32 // 每日限制 DailyLimit field.Int32 // 每日限制
DailyUsed field.Int32 // 今日已用数量 DailyUsed field.Int32 // 今日已用数量
DailyLast field.Field // 今日最后使用时间 DailyLast field.Field // 今日最后使用时间
CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间
fieldMap map[string]field.Expr fieldMap map[string]field.Expr
} }
@@ -89,9 +83,6 @@ func (r *resourcePss) updateTableName(table string) *resourcePss {
r.DailyLimit = field.NewInt32(table, "daily_limit") r.DailyLimit = field.NewInt32(table, "daily_limit")
r.DailyUsed = field.NewInt32(table, "daily_used") r.DailyUsed = field.NewInt32(table, "daily_used")
r.DailyLast = field.NewField(table, "daily_last") r.DailyLast = field.NewField(table, "daily_last")
r.CreatedAt = field.NewField(table, "created_at")
r.UpdatedAt = field.NewField(table, "updated_at")
r.DeletedAt = field.NewField(table, "deleted_at")
r.fillFieldMap() r.fillFieldMap()
@@ -108,7 +99,7 @@ func (r *resourcePss) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
} }
func (r *resourcePss) fillFieldMap() { func (r *resourcePss) fillFieldMap() {
r.fieldMap = make(map[string]field.Expr, 13) r.fieldMap = make(map[string]field.Expr, 10)
r.fieldMap["id"] = r.ID r.fieldMap["id"] = r.ID
r.fieldMap["resource_id"] = r.ResourceID r.fieldMap["resource_id"] = r.ResourceID
r.fieldMap["type"] = r.Type r.fieldMap["type"] = r.Type
@@ -119,9 +110,6 @@ func (r *resourcePss) fillFieldMap() {
r.fieldMap["daily_limit"] = r.DailyLimit r.fieldMap["daily_limit"] = r.DailyLimit
r.fieldMap["daily_used"] = r.DailyUsed r.fieldMap["daily_used"] = r.DailyUsed
r.fieldMap["daily_last"] = r.DailyLast r.fieldMap["daily_last"] = r.DailyLast
r.fieldMap["created_at"] = r.CreatedAt
r.fieldMap["updated_at"] = r.UpdatedAt
r.fieldMap["deleted_at"] = r.DeletedAt
} }
func (r resourcePss) clone(db *gorm.DB) resourcePss { func (r resourcePss) clone(db *gorm.DB) resourcePss {

View File

@@ -28,9 +28,10 @@ func ApplyRouters(app *fiber.App) {
whitelist.Post("/update", handlers.UpdateWhitelist) whitelist.Post("/update", handlers.UpdateWhitelist)
whitelist.Post("/remove", handlers.RemoveWhitelist) whitelist.Post("/remove", handlers.RemoveWhitelist)
// 资源 // 套餐
resource := api.Group("/resource") resource := api.Group("/resource")
resource.Post("/list/pss", handlers.ListResourcePss) resource.Post("/list/pss", handlers.ListResourcePss)
resource.Post("/all", handlers.AllResource)
resource.Post("/create/balance", handlers.CreateResourceByBalance) resource.Post("/create/balance", handlers.CreateResourceByBalance)
// 用户 // 用户

View File

@@ -12,7 +12,7 @@ import (
"platform/pkg/orm" "platform/pkg/orm"
"platform/pkg/rds" "platform/pkg/rds"
"platform/pkg/remote" "platform/pkg/remote"
"platform/pkg/v" "platform/pkg/u"
"platform/web/common" "platform/web/common"
"platform/web/models" "platform/web/models"
q "platform/web/queries" q "platform/web/queries"
@@ -37,12 +37,12 @@ const (
ChannelAuthTypePass ChannelAuthTypePass
) )
type ChannelProtocol string type ChannelProtocol int32
const ( const (
ProtocolSocks5 = ChannelProtocol("socks5") ProtocolHTTP = ChannelProtocol(1)
ProtocolHTTP = ChannelProtocol("http") ProtocolHttps = ChannelProtocol(2)
ProtocolHttps = ChannelProtocol("https") ProtocolSocks5 = ChannelProtocol(3)
) )
type ResourceInfo struct { type ResourceInfo struct {
@@ -142,7 +142,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
Port: int(channel.ProxyPort), Port: int(channel.ProxyPort),
Edge: &[]string{}, Edge: &[]string{},
AutoEdgeConfig: &remote.AutoEdgeConfig{ AutoEdgeConfig: &remote.AutoEdgeConfig{
Count: v.P(0), Count: u.P(0),
}, },
Status: false, Status: false,
} }
@@ -600,7 +600,7 @@ func assignPort(
Province: filter.Prov, Province: filter.Prov,
City: filter.City, City: filter.City,
Isp: filter.Isp, Isp: filter.Isp,
Count: v.P(1), Count: u.P(1),
PacketLoss: 30, PacketLoss: 30,
}, },
}) })
@@ -608,7 +608,7 @@ func assignPort(
switch authType { switch authType {
case ChannelAuthTypeIp: case ChannelAuthTypeIp:
configs[i].Whitelist = &whitelist configs[i].Whitelist = &whitelist
configs[i].Userpass = v.P("") configs[i].Userpass = u.P("")
for _, item := range whitelist { for _, item := range whitelist {
channels = append(channels, &models.Channel{ channels = append(channels, &models.Channel{
UserID: userId, UserID: userId,
@@ -617,19 +617,19 @@ func assignPort(
ProxyPort: int32(port), ProxyPort: int32(port),
AuthIP: true, AuthIP: true,
AuthPass: false, AuthPass: false,
Protocol: string(protocol), Protocol: int32(protocol),
Expiration: expiration, Expiration: expiration,
}) })
} }
result = append(result, &PortInfo{ result = append(result, &PortInfo{
Proto: string(protocol), Proto: protocol,
Host: proxy.Host, Host: proxy.Host,
Port: port, Port: port,
}) })
case ChannelAuthTypePass: case ChannelAuthTypePass:
username, password := genPassPair() username, password := genPassPair()
configs[i].Whitelist = &[]string{} configs[i].Whitelist = &[]string{}
configs[i].Userpass = v.P(fmt.Sprintf("%s:%s", username, password)) configs[i].Userpass = u.P(fmt.Sprintf("%s:%s", username, password))
channels = append(channels, &models.Channel{ channels = append(channels, &models.Channel{
UserID: userId, UserID: userId,
ProxyID: proxy.ID, ProxyID: proxy.ID,
@@ -638,11 +638,11 @@ func assignPort(
AuthPass: true, AuthPass: true,
Username: username, Username: username,
Password: password, Password: password,
Protocol: string(protocol), Protocol: int32(protocol),
Expiration: expiration, Expiration: expiration,
}) })
result = append(result, &PortInfo{ result = append(result, &PortInfo{
Proto: string(protocol), Proto: protocol,
Host: proxy.Host, Host: proxy.Host,
Port: port, Port: port,
Username: &username, Username: &username,
@@ -694,16 +694,17 @@ func assignPort(
} }
type PortInfo struct { type PortInfo struct {
Proto string `json:"-"` Proto ChannelProtocol `json:"-"`
Host string `json:"host"` Host string `json:"host"`
Port int `json:"port"` Port int `json:"port"`
Username *string `json:"username,omitempty"` Username *string `json:"username,omitempty"`
Password *string `json:"password,omitempty"` Password *string `json:"password,omitempty"`
} }
// endregion // endregion
func genPassPair() (string, string) { func genPassPair() (string, string) {
//goland:noinspection SpellCheckingInspection
var alphabet = []rune("abcdefghjkmnpqrstuvwxyz") var alphabet = []rune("abcdefghjkmnpqrstuvwxyz")
var numbers = []rune("23456789") var numbers = []rune("23456789")

View File

@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"platform/pkg/remote" "platform/pkg/remote"
"platform/pkg/testutil" "platform/pkg/testutil"
"platform/web/common"
"platform/web/models" "platform/web/models"
"reflect" "reflect"
"strings" "strings"
@@ -116,7 +117,7 @@ func Test_cache(t *testing.T) {
UserID: 100, UserID: 100,
ProxyID: 10, ProxyID: 10,
ProxyPort: 8080, ProxyPort: 8080,
Protocol: "http", Protocol: 1,
Expiration: expiration, Expiration: expiration,
}, },
{ {
@@ -124,7 +125,7 @@ func Test_cache(t *testing.T) {
UserID: 101, UserID: 101,
ProxyID: 11, ProxyID: 11,
ProxyPort: 8081, ProxyPort: 8081,
Protocol: "socks5", Protocol: 3,
Expiration: expiration, Expiration: expiration,
}, },
} }
@@ -330,7 +331,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
ResourceID: 1, ResourceID: 1,
Type: 1, Type: 1,
Live: 180, Live: 180,
Expire: time.Now().AddDate(1, 0, 0), Expire: common.LocalDateTime(time.Now().AddDate(1, 0, 0)),
DailyLimit: 10000, DailyLimit: 10000,
} }
db.Create(resourcePss) db.Create(resourcePss)
@@ -419,8 +420,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
// 验证结果 // 验证结果
var gotMap = make(map[int]PortInfo) var gotMap = make(map[int]PortInfo)
for _, port := range got { for _, port := range got {
if port.Proto != "http" { if port.Proto != 1 {
return fmt.Errorf("期望协议为 http得到 %s", port.Proto) return fmt.Errorf("期望协议为 1(http),得到 %d", port.Proto)
} }
if port.Host != proxy.Host { if port.Host != proxy.Host {
return fmt.Errorf("期望主机为 %s得到 %s", proxy.Host, port.Host) return fmt.Errorf("期望主机为 %s得到 %s", proxy.Host, port.Host)
@@ -432,8 +433,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
var channels []*models.Channel var channels []*models.Channel
db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels) db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels)
for _, ch := range channels { for _, ch := range channels {
if ch.Protocol != "http" { if ch.Protocol != 1 {
return fmt.Errorf("通道协议不正确,期望 http得到 %s", ch.Protocol) return fmt.Errorf("通道协议不正确,期望 1(http),得到 %d", ch.Protocol)
} }
if ch.UserID != userAuth.Payload.Id { if ch.UserID != userAuth.Payload.Id {
return fmt.Errorf("通道用户ID不正确期望 %d得到 %d", userAuth.Payload.Id, ch.UserID) return fmt.Errorf("通道用户ID不正确期望 %d得到 %d", userAuth.Payload.Id, ch.UserID)
@@ -449,8 +450,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
if ch.AuthPass != true && ch.AuthIP != false { if ch.AuthPass != true && ch.AuthIP != false {
return fmt.Errorf("通道认证类型不正确,期望 Pass得到 %v", ch.AuthPass) return fmt.Errorf("通道认证类型不正确,期望 Pass得到 %v", ch.AuthPass)
} }
if ch.Protocol != info.Proto { if ch.Protocol != int32(info.Proto) {
return fmt.Errorf("通道协议不正确,期望 %s,得到 %s", info.Proto, ch.Protocol) return fmt.Errorf("通道协议不正确,期望 %d,得到 %d", info.Proto, ch.Protocol)
} }
if ch.Username != *info.Username { if ch.Username != *info.Username {
return fmt.Errorf("通道用户名不正确,期望 %s得到 %s", *info.Username, ch.Username) return fmt.Errorf("通道用户名不正确,期望 %s得到 %s", *info.Username, ch.Username)
@@ -485,7 +486,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
if pss.DailyUsed != 3 { if pss.DailyUsed != 3 {
return fmt.Errorf("套餐每日用量不正确,期望 3得到 %d", pss.DailyUsed) return fmt.Errorf("套餐每日用量不正确,期望 3得到 %d", pss.DailyUsed)
} }
if pss.DailyLast.IsZero() { if time.Time(pss.DailyLast).IsZero() {
return fmt.Errorf("套餐每日最后更新时间不应为空") return fmt.Errorf("套餐每日最后更新时间不应为空")
} }
if pss.Used != 3 { if pss.Used != 3 {
@@ -569,8 +570,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
// 验证结果 // 验证结果
var gotMap = make(map[int]PortInfo) var gotMap = make(map[int]PortInfo)
for _, port := range got { for _, port := range got {
if port.Proto != "http" { if port.Proto != 1 {
return fmt.Errorf("期望协议为 http得到 %s", port.Proto) return fmt.Errorf("期望协议为 1(http),得到 %d", port.Proto)
} }
if port.Host != proxy.Host { if port.Host != proxy.Host {
return fmt.Errorf("期望主机为 %s得到 %s", proxy.Host, port.Host) return fmt.Errorf("期望主机为 %s得到 %s", proxy.Host, port.Host)
@@ -582,8 +583,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
var channels []*models.Channel var channels []*models.Channel
db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels) db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels)
for _, ch := range channels { for _, ch := range channels {
if ch.Protocol != "http" { if ch.Protocol != 1 {
return fmt.Errorf("通道协议不正确,期望 http得到 %s", ch.Protocol) return fmt.Errorf("通道协议不正确,期望 1(http),得到 %d", ch.Protocol)
} }
if ch.UserID != userAuth.Payload.Id { if ch.UserID != userAuth.Payload.Id {
return fmt.Errorf("通道用户ID不正确期望 %d得到 %d", userAuth.Payload.Id, ch.UserID) return fmt.Errorf("通道用户ID不正确期望 %d得到 %d", userAuth.Payload.Id, ch.UserID)
@@ -599,8 +600,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
if ch.AuthPass != false && ch.AuthIP != true { if ch.AuthPass != false && ch.AuthIP != true {
return fmt.Errorf("通道认证类型不正确,期望 Pass得到 %v", ch.AuthPass) return fmt.Errorf("通道认证类型不正确,期望 Pass得到 %v", ch.AuthPass)
} }
if ch.Protocol != info.Proto { if ch.Protocol != int32(info.Proto) {
return fmt.Errorf("通道协议不正确,期望 %s,得到 %s", info.Proto, ch.Protocol) return fmt.Errorf("通道协议不正确,期望 %d,得到 %d", info.Proto, ch.Protocol)
} }
if ch.Expiration.IsZero() { if ch.Expiration.IsZero() {
return fmt.Errorf("通道过期时间不应为空") return fmt.Errorf("通道过期时间不应为空")
@@ -629,7 +630,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
if pss.DailyUsed != 3 { if pss.DailyUsed != 3 {
return fmt.Errorf("套餐每日用量不正确,期望 3得到 %d", pss.DailyUsed) return fmt.Errorf("套餐每日用量不正确,期望 3得到 %d", pss.DailyUsed)
} }
if pss.DailyLast.IsZero() { if time.Time(pss.DailyLast).IsZero() {
return fmt.Errorf("套餐每日最后更新时间不应为空") return fmt.Errorf("套餐每日最后更新时间不应为空")
} }
if pss.Used != 3 { if pss.Used != 3 {
@@ -713,8 +714,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
// 验证结果 // 验证结果
var gotMap = make(map[int]PortInfo) var gotMap = make(map[int]PortInfo)
for _, port := range got { for _, port := range got {
if port.Proto != "socks5" { if port.Proto != 3 {
return fmt.Errorf("期望协议为 http得到 %s", port.Proto) return fmt.Errorf("期望协议为 1(http),得到 %d", port.Proto)
} }
if port.Host != proxy.Host { if port.Host != proxy.Host {
return fmt.Errorf("期望主机为 %s得到 %s", proxy.Host, port.Host) return fmt.Errorf("期望主机为 %s得到 %s", proxy.Host, port.Host)
@@ -726,8 +727,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
var channels []*models.Channel var channels []*models.Channel
db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels) db.Where("user_id = ? and deleted_at is null", userAuth.Payload.Id).Find(&channels)
for _, ch := range channels { for _, ch := range channels {
if ch.Protocol != "http" { if ch.Protocol != 1 {
return fmt.Errorf("通道协议不正确,期望 http得到 %s", ch.Protocol) return fmt.Errorf("通道协议不正确,期望 1(http),得到 %d", ch.Protocol)
} }
if ch.UserID != userAuth.Payload.Id { if ch.UserID != userAuth.Payload.Id {
return fmt.Errorf("通道用户ID不正确期望 %d得到 %d", userAuth.Payload.Id, ch.UserID) return fmt.Errorf("通道用户ID不正确期望 %d得到 %d", userAuth.Payload.Id, ch.UserID)
@@ -743,8 +744,8 @@ func Test_channelService_CreateChannel(t *testing.T) {
if ch.AuthPass != true && ch.AuthIP != false { if ch.AuthPass != true && ch.AuthIP != false {
return fmt.Errorf("通道认证类型不正确,期望 Pass得到 %v", ch.AuthPass) return fmt.Errorf("通道认证类型不正确,期望 Pass得到 %v", ch.AuthPass)
} }
if ch.Protocol != info.Proto { if ch.Protocol != int32(info.Proto) {
return fmt.Errorf("通道协议不正确,期望 %s,得到 %s", info.Proto, ch.Protocol) return fmt.Errorf("通道协议不正确,期望 %d,得到 %d", info.Proto, ch.Protocol)
} }
if ch.Username != *info.Username { if ch.Username != *info.Username {
return fmt.Errorf("通道用户名不正确,期望 %s得到 %s", *info.Username, ch.Username) return fmt.Errorf("通道用户名不正确,期望 %s得到 %s", *info.Username, ch.Username)
@@ -779,7 +780,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
if pss.DailyUsed != 3 { if pss.DailyUsed != 3 {
return fmt.Errorf("套餐每日用量不正确,期望 3得到 %d", pss.DailyUsed) return fmt.Errorf("套餐每日用量不正确,期望 3得到 %d", pss.DailyUsed)
} }
if pss.DailyLast.IsZero() { if time.Time(pss.DailyLast).IsZero() {
return fmt.Errorf("套餐每日最后更新时间不应为空") return fmt.Errorf("套餐每日最后更新时间不应为空")
} }
if pss.Used != 3 { if pss.Used != 3 {
@@ -831,7 +832,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
ResourceID: 2, ResourceID: 2,
Type: 1, Type: 1,
Live: 180, Live: 180,
Expire: time.Now().AddDate(1, 0, 0), Expire: common.LocalDateTime(time.Now().AddDate(1, 0, 0)),
DailyLimit: 10000, DailyLimit: 10000,
} }
db.Create(resourcePss2) db.Create(resourcePss2)
@@ -1022,9 +1023,9 @@ func Test_channelService_RemoveChannels(t *testing.T) {
// 创建通道 // 创建通道
channels := []models.Channel{ channels := []models.Channel{
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
{ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: "socks5", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: 3, Expiration: time.Now().Add(24 * time.Hour)},
} }
// 保存预设数据 // 保存预设数据
@@ -1136,9 +1137,9 @@ func Test_channelService_RemoveChannels(t *testing.T) {
// 创建通道 // 创建通道
channels := []models.Channel{ channels := []models.Channel{
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
{ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: "socks5", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 3, UserID: 101, ProxyID: 2, ProxyPort: 10001, Protocol: 3, Expiration: time.Now().Add(24 * time.Hour)},
} }
// 保存预设数据 // 保存预设数据
@@ -1250,9 +1251,9 @@ func Test_channelService_RemoveChannels(t *testing.T) {
// 创建通道 // 创建通道
channels := []models.Channel{ channels := []models.Channel{
{ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 1, UserID: 101, ProxyID: 1, ProxyPort: 10001, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
{ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: "http", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 2, UserID: 101, ProxyID: 1, ProxyPort: 10002, Protocol: 1, Expiration: time.Now().Add(24 * time.Hour)},
{ID: 3, UserID: 102, ProxyID: 2, ProxyPort: 10001, Protocol: "socks5", Expiration: time.Now().Add(24 * time.Hour)}, {ID: 3, UserID: 102, ProxyID: 2, ProxyPort: 10001, Protocol: 3, Expiration: time.Now().Add(24 * time.Hour)},
} }
// 保存预设数据 // 保存预设数据

View File

@@ -13,7 +13,7 @@ import (
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
) )
var ID IdService = IdService{} var ID = IdService{}
type IdService struct { type IdService struct {
} }

View File

@@ -11,6 +11,7 @@ import (
// 创建测试用的认证上下文 // 创建测试用的认证上下文
func createTestAuthContext() AuthContext { func createTestAuthContext() AuthContext {
//goland:noinspection ALL
return AuthContext{ return AuthContext{
Payload: Payload{ Payload: Payload{
Type: PayloadUser, Type: PayloadUser,

View File

@@ -2,6 +2,7 @@ package services
import ( import (
"context" "context"
"errors"
"platform/pkg/testutil" "platform/pkg/testutil"
"strconv" "strconv"
"testing" "testing"
@@ -85,8 +86,10 @@ func Test_verifierService_SendSms(t *testing.T) {
// 验证错误类型 // 验证错误类型
if tt.wantErr && tt.wantErrType != nil { if tt.wantErr && tt.wantErrType != nil {
if _, isSendLimitErr := err.(VerifierServiceSendLimitErr); isSendLimitErr { var verifierServiceSendLimitErr VerifierServiceSendLimitErr
if _, wantSendLimitErr := tt.wantErrType.(VerifierServiceSendLimitErr); !wantSendLimitErr { if errors.As(err, &verifierServiceSendLimitErr) {
var verifierServiceSendLimitErr VerifierServiceSendLimitErr
if !errors.As(tt.wantErrType, &verifierServiceSendLimitErr) {
t.Errorf("SendSms() error type = %T, wantErrType %T", err, tt.wantErrType) t.Errorf("SendSms() error type = %T, wantErrType %T", err, tt.wantErrType)
} }
} }
@@ -216,7 +219,7 @@ func Test_verifierService_VerifySms(t *testing.T) {
} }
// 检查错误类型 // 检查错误类型
if tt.wantErr && tt.wantErrType != nil && err != tt.wantErrType { if tt.wantErr && tt.wantErrType != nil && !errors.Is(err, tt.wantErrType) {
t.Errorf("VerifySms() error = %v, wantErrType %v", err, tt.wantErrType) t.Errorf("VerifySms() error = %v, wantErrType %v", err, tt.wantErrType)
return return
} }