提供一个测试注册代理接口
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"platform/pkg/u"
|
||||
"platform/web/core"
|
||||
"platform/web/globals/orm"
|
||||
m "platform/web/models"
|
||||
q "platform/web/queries"
|
||||
"time"
|
||||
@@ -10,6 +15,7 @@ var Proxy = &proxyService{}
|
||||
|
||||
type proxyService struct{}
|
||||
|
||||
// AllProxies 获取所有代理
|
||||
func (s *proxyService) AllProxies(proxyType m.ProxyType, channels bool) ([]*m.Proxy, error) {
|
||||
proxies, err := q.Proxy.Where(
|
||||
q.Proxy.Type.Eq(int(proxyType)),
|
||||
@@ -23,3 +29,36 @@ func (s *proxyService) AllProxies(proxyType m.ProxyType, channels bool) ([]*m.Pr
|
||||
|
||||
return proxies, nil
|
||||
}
|
||||
|
||||
// RegisterBaiyin 注册新代理服务
|
||||
func (s *proxyService) RegisterBaiyin(Mac string, IP netip.Addr, username, password string) error {
|
||||
|
||||
// 添加可用通道到 redis
|
||||
chans := make([]netip.AddrPort, 10000)
|
||||
for i := range 10000 {
|
||||
chans[i] = netip.AddrPortFrom(IP, uint16(i+10000))
|
||||
}
|
||||
err := registerChans(chans)
|
||||
if err != nil {
|
||||
return core.NewServErr("添加通道失败")
|
||||
}
|
||||
|
||||
// 保存代理信息
|
||||
if err := q.Proxy.Create(&m.Proxy{
|
||||
Version: 0,
|
||||
Mac: Mac,
|
||||
IP: orm.Inet{Addr: IP},
|
||||
Secret: u.P(fmt.Sprintf("%s:%s", username, password)),
|
||||
Type: m.ProxyTypeBaiYin,
|
||||
Status: m.ProxyStatusOnline,
|
||||
}); err != nil {
|
||||
return core.NewServErr("保存通道数据失败")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnregisterBaiyin 注销代理服务
|
||||
func (s *proxyService) UnregisterBaiyin(id int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user