config.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. Env json_util.RawMessage `json:"env,omitempty"`
  25. }
  26. // Equals compares two Config instances for deep equality.
  27. func (c *Config) Equals(other *Config) bool {
  28. if len(c.InboundConfigs) != len(other.InboundConfigs) {
  29. return false
  30. }
  31. for i, inbound := range c.InboundConfigs {
  32. if !inbound.Equals(&other.InboundConfigs[i]) {
  33. return false
  34. }
  35. }
  36. if !bytes.Equal(c.LogConfig, other.LogConfig) {
  37. return false
  38. }
  39. if !bytes.Equal(c.RouterConfig, other.RouterConfig) {
  40. return false
  41. }
  42. if !bytes.Equal(c.DNSConfig, other.DNSConfig) {
  43. return false
  44. }
  45. if !bytes.Equal(c.OutboundConfigs, other.OutboundConfigs) {
  46. return false
  47. }
  48. if !bytes.Equal(c.Transport, other.Transport) {
  49. return false
  50. }
  51. if !bytes.Equal(c.Policy, other.Policy) {
  52. return false
  53. }
  54. if !bytes.Equal(c.API, other.API) {
  55. return false
  56. }
  57. if !bytes.Equal(c.Stats, other.Stats) {
  58. return false
  59. }
  60. if !bytes.Equal(c.Reverse, other.Reverse) {
  61. return false
  62. }
  63. if !bytes.Equal(c.FakeDNS, other.FakeDNS) {
  64. return false
  65. }
  66. if !bytes.Equal(c.Observatory, other.Observatory) {
  67. return false
  68. }
  69. if !bytes.Equal(c.BurstObservatory, other.BurstObservatory) {
  70. return false
  71. }
  72. if !bytes.Equal(c.Metrics, other.Metrics) {
  73. return false
  74. }
  75. if !bytes.Equal(c.Geodata, other.Geodata) {
  76. return false
  77. }
  78. if !bytes.Equal(c.Env, other.Env) {
  79. return false
  80. }
  81. return true
  82. }