重构代码结构,迁移Baiyin SDK相关逻辑至globals包,并添加支付宝客户端初始化
This commit is contained in:
@@ -11,9 +11,9 @@ import (
|
||||
"platform/pkg/env"
|
||||
"platform/pkg/orm"
|
||||
"platform/pkg/rds"
|
||||
"platform/pkg/sdks/baiyin"
|
||||
"platform/pkg/u"
|
||||
"platform/web/common"
|
||||
g "platform/web/globals"
|
||||
"platform/web/models"
|
||||
q "platform/web/queries"
|
||||
"strconv"
|
||||
@@ -132,18 +132,18 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
|
||||
step = time.Now()
|
||||
|
||||
// 组织数据
|
||||
var configMap = make(map[int32][]baiyin.PortConfigsReq, len(proxies))
|
||||
var configMap = make(map[int32][]g.PortConfigsReq, len(proxies))
|
||||
var proxyMap = make(map[int32]*models.Proxy, len(proxies))
|
||||
for _, proxy := range proxies {
|
||||
configMap[proxy.ID] = make([]baiyin.PortConfigsReq, 0)
|
||||
configMap[proxy.ID] = make([]g.PortConfigsReq, 0)
|
||||
proxyMap[proxy.ID] = proxy
|
||||
}
|
||||
var portMap = make(map[uint64]struct{})
|
||||
for _, channel := range channels {
|
||||
var config = baiyin.PortConfigsReq{
|
||||
var config = g.PortConfigsReq{
|
||||
Port: int(channel.ProxyPort),
|
||||
Edge: &[]string{},
|
||||
AutoEdgeConfig: &baiyin.AutoEdgeConfig{
|
||||
AutoEdgeConfig: &g.AutoEdgeConfig{
|
||||
Count: u.P(0),
|
||||
},
|
||||
Status: false,
|
||||
@@ -167,7 +167,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
|
||||
}
|
||||
|
||||
var secret = strings.Split(proxy.Secret, ":")
|
||||
gateway := baiyin.NewGateway(
|
||||
gateway := g.NewGateway(
|
||||
proxy.Host,
|
||||
secret[0],
|
||||
secret[1],
|
||||
@@ -208,7 +208,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
|
||||
}
|
||||
}
|
||||
if len(edges) > 0 {
|
||||
_, err := baiyin.Cloud.CloudDisconnect(baiyin.CloudDisconnectReq{
|
||||
_, err := g.Cloud.CloudDisconnect(g.CloudDisconnectReq{
|
||||
Uuid: proxy.Name,
|
||||
Edge: edges,
|
||||
})
|
||||
@@ -406,7 +406,7 @@ func assignEdge(q *q.Query, count int, filter NodeFilterConfig) (*AssignEdgeResu
|
||||
// 查询已配置的节点
|
||||
step = time.Now()
|
||||
|
||||
rProxyConfigs, err := baiyin.Cloud.CloudAutoQuery()
|
||||
rProxyConfigs, err := g.Cloud.CloudAutoQuery()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -480,13 +480,13 @@ func assignEdge(q *q.Query, count int, filter NodeFilterConfig) (*AssignEdgeResu
|
||||
|
||||
rConfigs := rProxyConfigs[info.proxy.Name]
|
||||
|
||||
var newConfig = baiyin.AutoConfig{
|
||||
var newConfig = g.AutoConfig{
|
||||
Province: filter.Prov,
|
||||
City: filter.City,
|
||||
Isp: filter.Isp,
|
||||
Count: int(math.Ceil(float64(info.used) * 2)),
|
||||
}
|
||||
var newConfigs []baiyin.AutoConfig
|
||||
var newConfigs []g.AutoConfig
|
||||
var update = false
|
||||
for _, rConfig := range rConfigs {
|
||||
if rConfig.Isp == filter.Isp && rConfig.City == filter.City && rConfig.Province == filter.Prov {
|
||||
@@ -500,7 +500,7 @@ func assignEdge(q *q.Query, count int, filter NodeFilterConfig) (*AssignEdgeResu
|
||||
newConfigs = append(newConfigs, newConfig)
|
||||
}
|
||||
|
||||
err := baiyin.Cloud.CloudConnect(baiyin.CloudConnectReq{
|
||||
err := g.Cloud.CloudConnect(g.CloudConnectReq{
|
||||
Uuid: info.proxy.Name,
|
||||
Edge: nil,
|
||||
AutoConfig: newConfigs,
|
||||
@@ -587,7 +587,7 @@ func assignPort(
|
||||
var count = config.count
|
||||
|
||||
// 筛选可用端口
|
||||
var configs = make([]baiyin.PortConfigsReq, 0, count)
|
||||
var configs = make([]g.PortConfigsReq, 0, count)
|
||||
for port := 10000; port < 20000 && len(configs) < count; port++ {
|
||||
// 跳过存在的端口
|
||||
key := uint64(proxy.ID)<<32 | uint64(port)
|
||||
@@ -598,11 +598,11 @@ func assignPort(
|
||||
|
||||
// 配置新端口
|
||||
var i = len(configs)
|
||||
configs = append(configs, baiyin.PortConfigsReq{
|
||||
configs = append(configs, g.PortConfigsReq{
|
||||
Port: port,
|
||||
Edge: nil,
|
||||
Status: true,
|
||||
AutoEdgeConfig: &baiyin.AutoEdgeConfig{
|
||||
AutoEdgeConfig: &g.AutoEdgeConfig{
|
||||
Province: filter.Prov,
|
||||
City: filter.City,
|
||||
Isp: filter.Isp,
|
||||
@@ -682,7 +682,7 @@ func assignPort(
|
||||
step = time.Now()
|
||||
|
||||
var secret = strings.Split(proxy.Secret, ":")
|
||||
gateway := baiyin.NewGateway(
|
||||
gateway := g.NewGateway(
|
||||
proxy.Host,
|
||||
secret[0],
|
||||
secret[1],
|
||||
|
||||
Reference in New Issue
Block a user