package web import ( "context" "fmt" v1 "github.com/go-nunu/nunu-layout-advanced/api/v1" ) type Configure interface { ConfigureWebsocket(ctx context.Context, webId int64) error ConfigureProxyProtocol(ctx context.Context, proxy bool, cdnWebId int64) error ConfigureCCProtection(ctx context.Context, ccConfig v1.CcConfigRequest, webId int64) error ConfigureWafFirewall(ctx context.Context, webId int64, groupId int) error } // ConfigureWebsocket 配置WebSocket func (s *aidedWebService) ConfigureWebsocket(ctx context.Context, webId int64) error { websocketId, err := s.websocket.AddWebsocket(ctx) if err != nil { return fmt.Errorf("添加WebSocket失败: %w", err) } if err := s.websocket.EnableOrDisable(ctx, webId, websocketId, true, false); err != nil { return fmt.Errorf("启用WebSocket失败: %w", err) } return nil } // ConfigureProxyProtocol 配置代理协议 func (s *aidedWebService) ConfigureProxyProtocol(ctx context.Context, proxy bool, cdnWebId int64) error { if err := s.proxy.EditProxy(ctx, cdnWebId, v1.ProxyProtocolJSON{ IsOn: proxy, Version: proxyProtocolVersion, }); err != nil { return fmt.Errorf("启用代理协议失败: %w", err) } return nil } // ConfigureCCProtection 配置CC防护 func (s *aidedWebService) ConfigureCCProtection(ctx context.Context, ccConfig v1.CcConfigRequest, webId int64) error { if err := s.cc.EditCcConfig(ctx, webId, ccConfig); err != nil { return fmt.Errorf("配置CC防护失败: %w", err) } return nil } // ConfigureWafFirewall 配置WAF防火墙 func (s *aidedWebService) ConfigureWafFirewall(ctx context.Context, webId int64, groupId int) error { if err := s.ccIpList.AddCcIpListPolicy(ctx, webId, int64(groupId)); err != nil { return fmt.Errorf("配置WAF防火墙失败: %w", err) } return nil }