configure.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package web
  2. import (
  3. "context"
  4. "fmt"
  5. v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
  6. )
  7. // ConfigureWebsocket 配置WebSocket
  8. func (s *AidedWebService) ConfigureWebsocket(ctx context.Context, webId int64) error {
  9. websocketId, err := s.websocket.AddWebsocket(ctx)
  10. if err != nil {
  11. return fmt.Errorf("添加WebSocket失败: %w", err)
  12. }
  13. if err := s.websocket.EnableOrDisable(ctx, webId, websocketId, true, false); err != nil {
  14. return fmt.Errorf("启用WebSocket失败: %w", err)
  15. }
  16. return nil
  17. }
  18. // ConfigureProxyProtocol 配置代理协议
  19. func (s *AidedWebService) ConfigureProxyProtocol(ctx context.Context, proxy bool, cdnWebId int64) error {
  20. if err := s.proxy.EditProxy(ctx, cdnWebId, v1.ProxyProtocolJSON{
  21. IsOn: proxy,
  22. Version: proxyProtocolVersion,
  23. }); err != nil {
  24. return fmt.Errorf("启用代理协议失败: %w", err)
  25. }
  26. return nil
  27. }
  28. // ConfigureCCProtection 配置CC防护
  29. func (s *AidedWebService) ConfigureCCProtection(ctx context.Context, ccConfig v1.CcConfigRequest, webId int64) error {
  30. if err := s.cc.EditCcConfig(ctx, webId, ccConfig); err != nil {
  31. return fmt.Errorf("配置CC防护失败: %w", err)
  32. }
  33. return nil
  34. }
  35. // ConfigureWafFirewall 配置WAF防火墙
  36. func (s *AidedWebService) ConfigureWafFirewall(ctx context.Context, webId int64, groupId int) error {
  37. if err := s.ccIpList.AddCcIpListPolicy(ctx, webId, int64(groupId)); err != nil {
  38. return fmt.Errorf("配置WAF防火墙失败: %w", err)
  39. }
  40. return nil
  41. }