xray_setting.go 645 B

1234567891011121314151617181920212223242526272829
  1. package service
  2. import (
  3. _ "embed"
  4. "encoding/json"
  5. "x-ui/util/common"
  6. "x-ui/xray"
  7. )
  8. type XraySettingService struct {
  9. SettingService
  10. }
  11. func (s *XraySettingService) SaveXraySetting(newXraySettings string) error {
  12. if err := s.CheckXrayConfig(newXraySettings); err != nil {
  13. return err
  14. }
  15. return s.SettingService.saveSetting("xrayTemplateConfig", newXraySettings)
  16. }
  17. func (s *XraySettingService) CheckXrayConfig(XrayTemplateConfig string) error {
  18. xrayConfig := &xray.Config{}
  19. err := json.Unmarshal([]byte(XrayTemplateConfig), xrayConfig)
  20. if err != nil {
  21. return common.NewError("xray template config invalid:", err)
  22. }
  23. return nil
  24. }