|
@@ -33,6 +33,7 @@ func NewGlobalLimitService(
|
|
webLimit WebLimitService,
|
|
webLimit WebLimitService,
|
|
gateWayGroup GatewayGroupService,
|
|
gateWayGroup GatewayGroupService,
|
|
hostRep repository.HostRepository,
|
|
hostRep repository.HostRepository,
|
|
|
|
+ gateWayGroupRep repository.GatewayGroupRepository,
|
|
) GlobalLimitService {
|
|
) GlobalLimitService {
|
|
return &globalLimitService{
|
|
return &globalLimitService{
|
|
Service: service,
|
|
Service: service,
|
|
@@ -48,6 +49,7 @@ func NewGlobalLimitService(
|
|
webLimit: webLimit,
|
|
webLimit: webLimit,
|
|
gateWayGroup: gateWayGroup,
|
|
gateWayGroup: gateWayGroup,
|
|
hostRep: hostRep,
|
|
hostRep: hostRep,
|
|
|
|
+ gateWayGroupRep: gateWayGroupRep,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -65,6 +67,7 @@ type globalLimitService struct {
|
|
webLimit WebLimitService
|
|
webLimit WebLimitService
|
|
gateWayGroup GatewayGroupService
|
|
gateWayGroup GatewayGroupService
|
|
hostRep repository.HostRepository
|
|
hostRep repository.HostRepository
|
|
|
|
+ gateWayGroupRep repository.GatewayGroupRepository
|
|
}
|
|
}
|
|
|
|
|
|
func (s *globalLimitService) GlobalLimitRequire(ctx context.Context, req v1.GlobalLimitRequest) (res v1.GlobalLimitRequireResponse, err error) {
|
|
func (s *globalLimitService) GlobalLimitRequire(ctx context.Context, req v1.GlobalLimitRequest) (res v1.GlobalLimitRequireResponse, err error) {
|
|
@@ -86,6 +89,8 @@ func (s *globalLimitService) GlobalLimitRequire(ctx context.Context, req v1.Glob
|
|
|
|
|
|
res.Bps = configCount.Bps
|
|
res.Bps = configCount.Bps
|
|
res.MaxBytesMonth = configCount.MaxBytesMonth
|
|
res.MaxBytesMonth = configCount.MaxBytesMonth
|
|
|
|
+ res.Operator = configCount.Operator
|
|
|
|
+ res.IpCount = configCount.IpCount
|
|
domain, err := s.hostRep.GetDomainById(ctx, req.HostId)
|
|
domain, err := s.hostRep.GetDomainById(ctx, req.HostId)
|
|
if err != nil {
|
|
if err != nil {
|
|
return v1.GlobalLimitRequireResponse{}, err
|
|
return v1.GlobalLimitRequireResponse{}, err
|
|
@@ -103,6 +108,10 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+ gatewayGroupId, err := s.gateWayGroupRep.GetGatewayGroupWhereHostIdNull(ctx, require.Operator, require.IpCount)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
formData := map[string]interface{}{
|
|
formData := map[string]interface{}{
|
|
"tag": require.GlobalLimitName,
|
|
"tag": require.GlobalLimitName,
|
|
"bps": require.Bps,
|
|
"bps": require.Bps,
|
|
@@ -193,6 +202,7 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
if err := g.Wait(); err != nil {
|
|
if err := g.Wait(); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
err = s.globalLimitRepository.AddGlobalLimit(ctx, &model.GlobalLimit{
|
|
err = s.globalLimitRepository.AddGlobalLimit(ctx, &model.GlobalLimit{
|
|
HostId: req.HostId,
|
|
HostId: req.HostId,
|
|
RuleId: cast.ToInt(ruleId),
|
|
RuleId: cast.ToInt(ruleId),
|
|
@@ -201,11 +211,15 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
TcpLimitRuleId: tcpLimitRuleId,
|
|
TcpLimitRuleId: tcpLimitRuleId,
|
|
UdpLimitRuleId: udpLimitRuleId,
|
|
UdpLimitRuleId: udpLimitRuleId,
|
|
WebLimitRuleId: webLimitRuleId,
|
|
WebLimitRuleId: webLimitRuleId,
|
|
- GatewayGroupId: 5,// TODO: 临时写死
|
|
|
|
|
|
+ GatewayGroupId: gatewayGroupId,
|
|
})
|
|
})
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+ err = s.gateWayGroupRep.EditGatewayGroup(ctx, &model.GatewayGroup{
|
|
|
|
+ RuleId: gatewayGroupId,
|
|
|
|
+ HostId: req.HostId,
|
|
|
|
+ })
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|