Browse Source

refactor(webforwarding): 重构代理配置生成逻辑

- 移除了未使用的 proxyTypeSuffix 变量
- 修改了 buildProxyJSONConfig 函数签名,移除了返回值 apiType
- 将 formData.Type 固定设置为 "httpProxy"
- 更新了错误处理,移除了不必要的空格
fusu 1 month ago
parent
commit
66c6b3dbf4
1 changed files with 6 additions and 7 deletions
  1. 6 7
      internal/service/webforwarding.go

+ 6 - 7
internal/service/webforwarding.go

@@ -70,7 +70,6 @@ const (
 	isHttps         = 1
 	protocolHttps        = "https"
 	protocolHttp         = "http"
-	proxyTypeSuffix      = "Proxy"
 	defaultNodeClusterId = 1
 )
 func (s *webForwardingService) require(ctx context.Context,req v1.GlobalRequire) (v1.GlobalRequire, error) {
@@ -199,7 +198,7 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
 	}
 
 	// 2. 调用辅助函数,构建核心的代理配置 (将复杂逻辑封装起来)
-	apiType, byteData, err := s.buildProxyJSONConfig(ctx, req, require)
+	byteData, err := s.buildProxyJSONConfig(ctx, req, require)
 	if err != nil {
 		return RequireResponse{}, v1.Website{}, err // 错误信息在辅助函数中已经包装好了
 	}
@@ -224,7 +223,7 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
 	// 3. 组装最终的 WAF 表单数据
 	formData := v1.Website{
 		UserId:         int64(require.CdnUid),
-		Type:           apiType + proxyTypeSuffix,
+		Type:           "httpProxy",
 		Name:           require.Tag,
 		ServerNamesJSON : serverJson,
 		Description:    req.WebForwardingData.Comment,
@@ -252,7 +251,7 @@ func (s *webForwardingService) prepareWafData(ctx context.Context, req *v1.WebFo
 // 辅助函数:buildProxyJSONConfig
 // 职责:专门负责处理 HTTP/HTTPS 的差异,并生成对应的 JSON 配置。
 // =================================================================
-func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1.WebForwardingRequest, require RequireResponse) (string, []byte, error) {
+func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1.WebForwardingRequest, require RequireResponse) ([]byte, error) {
 	var (
 		jsonData v1.TypeJSON
 		apiType  string
@@ -273,7 +272,7 @@ func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1
 			IsSelfSigned: false,
 		})
 		if err != nil {
-			return "", nil, fmt.Errorf("添加SSL证书失败: %w", err)
+			return  nil, fmt.Errorf("添加SSL证书失败: %w", err)
 		}
 		jsonData.SslPolicyRef.IsOn = true
 		jsonData.SslPolicyRef.SslPolicyId = req.WebForwardingData.SslCertId
@@ -293,10 +292,10 @@ func (s *webForwardingService) buildProxyJSONConfig(ctx context.Context, req *v1
 	// 序列化为 JSON
 	byteData, err := json.Marshal(jsonData)
 	if err != nil {
-		return "", nil, fmt.Errorf("序列化WAF配置失败: %w", err)
+		return nil, fmt.Errorf("序列化WAF配置失败: %w", err)
 	}
 
-	return apiType, byteData, nil
+	return  byteData, nil
 }
 
 // 查找两个列表的差异