数据模型使用指针类型字段以避免空值自动更新的问题
This commit is contained in:
@@ -163,8 +163,11 @@ func removeShortChannelExternal(proxies []*m.Proxy, channels []*m.Channel) error
|
||||
if !ok {
|
||||
return core.NewBizErr("代理不存在")
|
||||
}
|
||||
if proxy.Secret == nil {
|
||||
return core.NewBizErr("代理未配置密钥")
|
||||
}
|
||||
|
||||
var secret = strings.Split(proxy.Secret, ":")
|
||||
var secret = strings.Split(*proxy.Secret, ":")
|
||||
gateway := g.NewGateway(
|
||||
proxy.Host,
|
||||
secret[0],
|
||||
@@ -322,27 +325,53 @@ func findResource(q *q.Query, resourceId int32, userId int32, count int, now tim
|
||||
Active: resource.Active,
|
||||
Type: resource2.Type(resource.Type),
|
||||
}
|
||||
|
||||
switch resource2.Type(resource.Type) {
|
||||
case resource2.TypeShort:
|
||||
var sub = resource.Short
|
||||
var dailyLast = time.Time{}
|
||||
if sub.DailyLast != nil {
|
||||
dailyLast = time.Time(*sub.DailyLast)
|
||||
}
|
||||
var expire = time.Time{}
|
||||
if sub.Expire != nil {
|
||||
expire = time.Time(*sub.Expire)
|
||||
}
|
||||
var quota int32
|
||||
if sub.Quota != nil {
|
||||
quota = *sub.Quota
|
||||
}
|
||||
info.Mode = resource2.Mode(sub.Type)
|
||||
info.Live = sub.Live
|
||||
info.DailyLimit = sub.DailyLimit
|
||||
info.DailyUsed = sub.DailyUsed
|
||||
info.DailyLast = time.Time(sub.DailyLast)
|
||||
info.Quota = sub.Quota
|
||||
info.DailyLast = dailyLast
|
||||
info.Expire = expire
|
||||
info.Quota = quota
|
||||
info.Used = sub.Used
|
||||
info.Expire = time.Time(sub.Expire)
|
||||
|
||||
case resource2.TypeLong:
|
||||
var sub = resource.Long
|
||||
var dailyLast = time.Time{}
|
||||
if sub.DailyLast != nil {
|
||||
dailyLast = time.Time(*sub.DailyLast)
|
||||
}
|
||||
var expire = time.Time{}
|
||||
if sub.Expire != nil {
|
||||
expire = time.Time(*sub.Expire)
|
||||
}
|
||||
var quota int32
|
||||
if sub.Quota != nil {
|
||||
quota = *sub.Quota
|
||||
}
|
||||
info.Mode = resource2.Mode(sub.Type)
|
||||
info.Live = sub.Live
|
||||
info.DailyLimit = sub.DailyLimit
|
||||
info.DailyUsed = sub.DailyUsed
|
||||
info.DailyLast = time.Time(sub.DailyLast)
|
||||
info.Quota = sub.Quota
|
||||
info.DailyLast = dailyLast
|
||||
info.Expire = expire
|
||||
info.Quota = quota
|
||||
info.Used = sub.Used
|
||||
info.Expire = time.Time(sub.Expire)
|
||||
}
|
||||
|
||||
// 检查套餐状态
|
||||
@@ -544,22 +573,22 @@ func assignShortChannels(q *q.Query, userId int32, resourceId int32, count int,
|
||||
ResourceID: resourceId,
|
||||
ProxyHost: proxy.Host,
|
||||
ProxyPort: int32(port),
|
||||
Protocol: int32(config.Protocol),
|
||||
Protocol: u.P(int32(config.Protocol)),
|
||||
Expiration: orm.LocalDateTime(config.Expiration),
|
||||
}
|
||||
|
||||
if config.AuthIp {
|
||||
portConf.Whitelist = &config.Whitelists
|
||||
newChannel.AuthIP = true
|
||||
newChannel.Whitelists = strings.Join(config.Whitelists, ",")
|
||||
newChannel.Whitelists = u.P(strings.Join(config.Whitelists, ","))
|
||||
}
|
||||
|
||||
if config.AuthPass {
|
||||
username, password := genPassPair()
|
||||
portConf.Userpass = u.P(fmt.Sprintf("%s:%s", username, password))
|
||||
newChannel.AuthPass = true
|
||||
newChannel.Username = username
|
||||
newChannel.Password = password
|
||||
newChannel.Username = &username
|
||||
newChannel.Password = &password
|
||||
}
|
||||
|
||||
portConfigs = append(portConfigs, portConf)
|
||||
@@ -572,8 +601,10 @@ func assignShortChannels(q *q.Query, userId int32, resourceId int32, count int,
|
||||
// 提交端口配置
|
||||
if env.DebugExternalChange {
|
||||
var step = time.Now()
|
||||
|
||||
var secret = strings.Split(proxy.Secret, ":")
|
||||
if proxy.Secret == nil {
|
||||
return nil, core.NewBizErr("代理未配置密钥")
|
||||
}
|
||||
var secret = strings.Split(*proxy.Secret, ":")
|
||||
gateway := g.NewGateway(
|
||||
proxy.Host,
|
||||
secret[0],
|
||||
@@ -648,11 +679,14 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
var proxies = make(map[int32]*m.Proxy)
|
||||
var reqs = make(map[int32][]*g.ProxyPermitConfig)
|
||||
for _, edge := range edges {
|
||||
if _, ok := proxies[edge.ProxyID]; !ok {
|
||||
proxies[edge.ProxyID] = &m.Proxy{
|
||||
ID: edge.ProxyID,
|
||||
if edge.ProxyID == nil || edge.ProxyPort == nil {
|
||||
return nil, core.NewBizErr("节点配置不完整,缺少代理信息")
|
||||
}
|
||||
if _, ok := proxies[*edge.ProxyID]; !ok {
|
||||
proxies[*edge.ProxyID] = &m.Proxy{
|
||||
ID: *edge.ProxyID,
|
||||
Host: edge.ProxyHost,
|
||||
Secret: edge.ProxySecret,
|
||||
Secret: &edge.ProxySecret,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,28 +702,28 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
for range acc {
|
||||
var channel = &m.Channel{
|
||||
UserID: userId,
|
||||
ProxyID: edge.ProxyID,
|
||||
EdgeID: edge.ID,
|
||||
ProxyID: *edge.ProxyID,
|
||||
EdgeID: &edge.ID,
|
||||
ResourceID: resourceId,
|
||||
Protocol: int32(config.Protocol),
|
||||
Protocol: u.P(int32(config.Protocol)),
|
||||
AuthIP: config.AuthIp,
|
||||
AuthPass: config.AuthPass,
|
||||
Expiration: orm.LocalDateTime(config.Expiration),
|
||||
ProxyHost: edge.ProxyHost,
|
||||
ProxyPort: edge.ProxyPort,
|
||||
ProxyPort: *edge.ProxyPort,
|
||||
}
|
||||
if config.AuthIp {
|
||||
channel.Whitelists = strings.Join(config.Whitelists, ",")
|
||||
channel.Whitelists = u.P(strings.Join(config.Whitelists, ","))
|
||||
}
|
||||
if config.AuthPass {
|
||||
username, password := genPassPair()
|
||||
channel.Username = username
|
||||
channel.Password = password
|
||||
channel.Username = &username
|
||||
channel.Password = &password
|
||||
}
|
||||
channels = append(channels, channel)
|
||||
|
||||
req := &g.ProxyPermitConfig{
|
||||
Id: channel.EdgeID,
|
||||
Id: *channel.EdgeID,
|
||||
Expire: time.Time(channel.Expiration),
|
||||
}
|
||||
|
||||
@@ -698,11 +732,11 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
}
|
||||
|
||||
if channel.AuthPass {
|
||||
req.Username = &channel.Username
|
||||
req.Password = &channel.Password
|
||||
req.Username = channel.Username
|
||||
req.Password = channel.Password
|
||||
}
|
||||
|
||||
reqs[edge.ProxyID] = append(reqs[edge.ProxyID], req)
|
||||
reqs[*edge.ProxyID] = append(reqs[*edge.ProxyID], req)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -711,7 +745,7 @@ func assignLongChannels(q *q.Query, userId int32, resourceId int32, count int, c
|
||||
var step = time.Now()
|
||||
for id, reqs := range reqs {
|
||||
proxy := proxies[id]
|
||||
err := g.Proxy.Permit(proxy.Host, proxy.Secret, reqs)
|
||||
err := g.Proxy.Permit(proxy.Host, *proxy.Secret, reqs)
|
||||
if err != nil {
|
||||
return nil, core.NewBizErr("提交端口配置失败", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user