config.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package xray
  2. import (
  3. "bytes"
  4. "github.com/mhsanaei/3x-ui/v3/internal/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,omitempty"`
  12. InboundConfigs []InboundConfig `json:"inbounds"`
  13. OutboundConfigs json_util.RawMessage `json:"outbounds"`
  14. Transport json_util.RawMessage `json:"transport,omitempty"`
  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,omitempty"`
  19. FakeDNS json_util.RawMessage `json:"fakedns,omitempty"`
  20. Observatory json_util.RawMessage `json:"observatory,omitempty"`
  21. BurstObservatory json_util.RawMessage `json:"burstObservatory,omitempty"`
  22. Metrics json_util.RawMessage `json:"metrics"`
  23. Geodata json_util.RawMessage `json:"geodata,omitempty"`
  24. }
  25. // Equals compares two Config instances for deep equality.
  26. func (c *Config) Equals(other *Config) bool {
  27. if len(c.InboundConfigs) != len(other.InboundConfigs) {
  28. return false
  29. }
  30. for i, inbound := range c.InboundConfigs {
  31. if !inbound.Equals(&other.InboundConfigs[i]) {
  32. return false
  33. }
  34. }
  35. if !bytes.Equal(c.LogConfig, other.LogConfig) {
  36. return false
  37. }
  38. if !bytes.Equal(c.RouterConfig, other.RouterConfig) {
  39. return false
  40. }
  41. if !bytes.Equal(c.DNSConfig, other.DNSConfig) {
  42. return false
  43. }
  44. if !bytes.Equal(c.OutboundConfigs, other.OutboundConfigs) {
  45. return false
  46. }
  47. if !bytes.Equal(c.Transport, other.Transport) {
  48. return false
  49. }
  50. if !bytes.Equal(c.Policy, other.Policy) {
  51. return false
  52. }
  53. if !bytes.Equal(c.API, other.API) {
  54. return false
  55. }
  56. if !bytes.Equal(c.Stats, other.Stats) {
  57. return false
  58. }
  59. if !bytes.Equal(c.Reverse, other.Reverse) {
  60. return false
  61. }
  62. if !bytes.Equal(c.FakeDNS, other.FakeDNS) {
  63. return false
  64. }
  65. if !bytes.Equal(c.Metrics, other.Metrics) {
  66. return false
  67. }
  68. if !bytes.Equal(c.Geodata, other.Geodata) {
  69. return false
  70. }
  71. return true
  72. }