修改事务提交调用问题
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,6 +5,6 @@
|
|||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
|
||||||
build/
|
bin/
|
||||||
|
|
||||||
*.http
|
*.http
|
||||||
36
build.ps1
Normal file
36
build.ps1
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
Remove-Job *
|
||||||
|
|
||||||
|
$tasks = 0
|
||||||
|
$start = Get-Date
|
||||||
|
|
||||||
|
$tasks++
|
||||||
|
Write-Output "building platform for linux amd64..."
|
||||||
|
Start-Job -ScriptBlock {
|
||||||
|
$env:GOOS = "linux"; $env:GOARCH = "amd64"; go build -ldflags '-w -s' -o bin/platform_linux_amd64 cmd/main/main.go
|
||||||
|
} | Out-Null
|
||||||
|
|
||||||
|
$tasks++
|
||||||
|
Write-Output "building tasks for linux amd64..."
|
||||||
|
Start-Job -ScriptBlock {
|
||||||
|
$env:GOOS = "linux"; $env:GOARCH = "amd64"; go build -ldflags '-w -s' -o bin/tasks_linux_amd64 cmd/tasks/main.go
|
||||||
|
} | Out-Null
|
||||||
|
|
||||||
|
# Wait for all jobs to complete
|
||||||
|
while ($tasks -gt 0)
|
||||||
|
{
|
||||||
|
foreach ($job in Get-Job)
|
||||||
|
{
|
||||||
|
if ($job.State -eq "Completed")
|
||||||
|
{
|
||||||
|
$tasks--
|
||||||
|
$job | Receive-Job
|
||||||
|
$job | Remove-Job
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$end = Get-Date
|
||||||
|
|
||||||
|
Write-Output "build completed"
|
||||||
|
Write-Output "time taken: $( ($end - $start).TotalSeconds ) seconds"
|
||||||
|
Write-Output "output files are in ./bin/"
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
// SetupDBTest 创建一个基于 SQLite 内存数据库的 GORM 连接
|
// SetupDBTest 创建一个基于 SQLite 内存数据库的 GORM 连接
|
||||||
func SetupDBTest(t *testing.T) *gorm.DB {
|
func SetupDBTest(t *testing.T) *gorm.DB {
|
||||||
// 使用 SQLite 内存数据库
|
// 使用 SQLite 内存数据库
|
||||||
gormDB, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
|
gormDB, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("gorm 打开 SQLite 内存数据库失败: %v", err)
|
t.Fatalf("gorm 打开 SQLite 内存数据库失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ func (s *channelService) CreateChannel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var addr []*PortInfo
|
var addr []*PortInfo
|
||||||
err := q.Q.Transaction(func(tx *q.Query) error {
|
err := q.Q.Transaction(func(q *q.Query) error {
|
||||||
|
|
||||||
// 查找套餐
|
// 查找套餐
|
||||||
step = time.Now()
|
step = time.Now()
|
||||||
@@ -285,7 +285,7 @@ func (s *channelService) CreateChannel(
|
|||||||
// 申请节点
|
// 申请节点
|
||||||
step = time.Now()
|
step = time.Now()
|
||||||
|
|
||||||
edgeAssigns, err := assignEdge(count, filter)
|
edgeAssigns, err := assignEdge(q, count, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,7 @@ func (s *channelService) CreateChannel(
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
expiration := now.Add(time.Duration(resource.Live) * time.Second)
|
expiration := now.Add(time.Duration(resource.Live) * time.Second)
|
||||||
_addr, channels, err := assignPort(edgeAssigns, auth.Payload.Id, protocol, authType, expiration, filter)
|
_addr, channels, err := assignPort(q, edgeAssigns, auth.Payload.Id, protocol, authType, expiration, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -386,7 +386,7 @@ func checkUser(auth *AuthContext, resource *ResourceInfo, count int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assignEdge 分配边缘节点数量
|
// assignEdge 分配边缘节点数量
|
||||||
func assignEdge(count int, filter NodeFilterConfig) (*AssignEdgeResult, error) {
|
func assignEdge(q *q.Query, count int, filter NodeFilterConfig) (*AssignEdgeResult, error) {
|
||||||
|
|
||||||
// 查询可以使用的网关
|
// 查询可以使用的网关
|
||||||
var step = time.Now()
|
var step = time.Now()
|
||||||
@@ -539,6 +539,7 @@ type ProxyConfig struct {
|
|||||||
|
|
||||||
// assignPort 分配指定数量的端口
|
// assignPort 分配指定数量的端口
|
||||||
func assignPort(
|
func assignPort(
|
||||||
|
q *q.Query,
|
||||||
proxies *AssignEdgeResult,
|
proxies *AssignEdgeResult,
|
||||||
userId int32,
|
userId int32,
|
||||||
protocol ChannelProtocol,
|
protocol ChannelProtocol,
|
||||||
@@ -718,8 +719,7 @@ func genPassPair() (string, string) {
|
|||||||
password[i] = letters[rand.N(len(letters))]
|
password[i] = letters[rand.N(len(letters))]
|
||||||
}
|
}
|
||||||
|
|
||||||
// return string(username), string(password)
|
return string(username), string(password)
|
||||||
return "123123", "123123"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func chKey(channel *models.Channel) string {
|
func chKey(channel *models.Channel) string {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"platform/pkg/remote"
|
"platform/pkg/remote"
|
||||||
"platform/pkg/testutil"
|
"platform/pkg/testutil"
|
||||||
"platform/web/models"
|
"platform/web/models"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -337,7 +338,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
setup func()
|
setup func()
|
||||||
want []string
|
want []*PortInfo
|
||||||
wantErr bool
|
wantErr bool
|
||||||
wantErrContains string
|
wantErrContains string
|
||||||
checkCache func(channels []models.Channel) error
|
checkCache func(channels []models.Channel) error
|
||||||
@@ -353,10 +354,12 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
|||||||
count: 3,
|
count: 3,
|
||||||
nodeFilter: []NodeFilterConfig{{Prov: "河南", City: "郑州", Isp: "电信"}},
|
nodeFilter: []NodeFilterConfig{{Prov: "河南", City: "郑州", Isp: "电信"}},
|
||||||
},
|
},
|
||||||
want: []string{
|
want: []*PortInfo{
|
||||||
"http://111.111.111.111:10000",
|
{
|
||||||
"http://111.111.111.111:10001",
|
Proto: "http",
|
||||||
"http://111.111.111.111:10002",
|
Host: proxy.Host,
|
||||||
|
Port: 10000,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -369,10 +372,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
|||||||
authType: ChannelAuthTypeIp,
|
authType: ChannelAuthTypeIp,
|
||||||
count: 2,
|
count: 2,
|
||||||
},
|
},
|
||||||
want: []string{
|
want: []*PortInfo{},
|
||||||
"http://111.111.111.111:10000",
|
|
||||||
"http://111.111.111.111:10001",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "管理员创建SOCKS5密码通道",
|
name: "管理员创建SOCKS5密码通道",
|
||||||
@@ -384,10 +384,7 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
|||||||
authType: ChannelAuthTypePass,
|
authType: ChannelAuthTypePass,
|
||||||
count: 2,
|
count: 2,
|
||||||
},
|
},
|
||||||
want: []string{
|
want: []*PortInfo{},
|
||||||
"socks5://111.111.111.111:10000",
|
|
||||||
"socks5://111.111.111.111:10001",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "套餐不存在",
|
name: "套餐不存在",
|
||||||
@@ -507,9 +504,9 @@ func Test_channelService_CreateChannel(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(got) != len(tt.want) {
|
// 检查返回值
|
||||||
t.Errorf("CreateChannel() 返回长度 = %v, want %v", len(got), len(tt.want))
|
if reflect.DeepEqual(got, tt.want) {
|
||||||
return
|
t.Errorf("CreateChannel() 返回值 = %v, 期望 %v", got, tt.want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询创建的通道
|
// 查询创建的通道
|
||||||
|
|||||||
Reference in New Issue
Block a user