config.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package xray
  2. import (
  3. "bytes"
  4. "github.com/mhsanaei/3x-ui/v2/util/json_util"
  5. )
  6. // Config represents the complete Xray configuration structure.
  7. // It contains all sections of an Xray config file including inbounds, outbounds, routing, etc.
  8. type Config struct {
  9. LogConfig json_util.RawMessage `json:"log"`
  10. RouterConfig json_util.RawMessage `json:"routing"`
  11. DNSConfig json_util.RawMessage `json:"dns"`
  12. InboundConfigs []InboundConfig `json:"inbounds"`
  13. OutboundConfigs json_util.RawMessage `json:"outbounds"`
  14. Transport json_util.RawMessage `json:"transport"`
  15. Policy json_util.RawMessage `json:"policy"`
  16. API json_util.RawMessage `json:"api"`
  17. Stats json_util.RawMessage `json:"stats"`
  18. Reverse json_util.RawMessage `json:"reverse"`
  19. FakeDNS json_util.RawMessage `json:"fakedns"`
  20. Observatory json_util.RawMessage `json:"observatory"`
  21. BurstObservatory json_util.RawMessage `json:"burstObservatory"`
  22. Metrics json_util.RawMessage `json:"metrics"`
  23. }
  24. // Equals compares two Config instances for deep equality.
  25. func (c *Config) Equals(other *Config) bool {
  26. if len(c.InboundConfigs) != len(other.InboundConfigs) {
  27. return false
  28. }
  29. for i, inbound := range c.InboundConfigs {
  30. if !inbound.Equals(&other.InboundConfigs[i]) {
  31. return false
  32. }
  33. }
  34. if !bytes.Equal(c.LogConfig, other.LogConfig) {
  35. return false
  36. }
  37. if !bytes.Equal(c.RouterConfig, other.RouterConfig) {
  38. return false
  39. }
  40. if !bytes.Equal(c.DNSConfig, other.DNSConfig) {
  41. return false
  42. }
  43. if !bytes.Equal(c.OutboundConfigs, other.OutboundConfigs) {
  44. return false
  45. }
  46. if !bytes.Equal(c.Transport, other.Transport) {
  47. return false
  48. }
  49. if !bytes.Equal(c.Policy, other.Policy) {
  50. return false
  51. }
  52. if !bytes.Equal(c.API, other.API) {
  53. return false
  54. }
  55. if !bytes.Equal(c.Stats, other.Stats) {
  56. return false
  57. }
  58. if !bytes.Equal(c.Reverse, other.Reverse) {
  59. return false
  60. }
  61. if !bytes.Equal(c.FakeDNS, other.FakeDNS) {
  62. return false
  63. }
  64. if !bytes.Equal(c.Metrics, other.Metrics) {
  65. return false
  66. }
  67. return true
  68. }