Browse Source

refactor(waf): 优化代理协议配置逻辑

- 简化了 ConfigureProxyProtocol 函数的逻辑
- 移除了不必要的 if 嵌套,提高了代码可读性
- 统一处理了 proxy 参数,避免了重复代码
fusu 1 day ago
parent
commit
2a0512f238
1 changed files with 5 additions and 7 deletions
  1. 5 7
      internal/service/api/waf/aidedweb.go

+ 5 - 7
internal/service/api/waf/aidedweb.go

@@ -807,13 +807,11 @@ func (s *aidedWebService) ConfigureWebsocket(ctx context.Context, webId int64) e
 
 // ConfigureProxyProtocol 配置代理协议
 func (s *aidedWebService) ConfigureProxyProtocol(ctx context.Context, proxy bool, webId int64) error {
-	if proxy {
-		if err := s.proxy.EditProxy(ctx, webId, v1.ProxyProtocolJSON{
-			IsOn:    true,
-			Version: proxyProtocolVersion,
-		}); err != nil {
-			return fmt.Errorf("启用代理协议失败: %w", err)
-		}
+	if err := s.proxy.EditProxy(ctx, webId, v1.ProxyProtocolJSON{
+		IsOn:    proxy,
+		Version: proxyProtocolVersion,
+	}); err != nil {
+		return fmt.Errorf("启用代理协议失败: %w", err)
 	}
 	return nil
 }