mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
Config: Implement missing MarshalJSON for structs having custom UnmarshalJSON (#4585)
* conf: implement MarshalJSON for FakeDNSConfig * conf: Rewrite MarshalJSON for PortList decouple PortRange from PortList. * conf: implement MarshalJSON for HostAddress * conf: Add MarshalJSON comments and use pointers.
This commit is contained in:
parent
0dbab7bcd7
commit
2d3126b752
4 changed files with 63 additions and 11 deletions
|
@ -20,6 +20,18 @@ type FakeDNSConfig struct {
|
|||
pools []*FakeDNSPoolElementConfig
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.MarshalJSON
|
||||
func (f *FakeDNSConfig) MarshalJSON() ([]byte, error) {
|
||||
if (f.pool != nil) != (f.pools != nil) {
|
||||
if f.pool != nil {
|
||||
return json.Marshal(f.pool)
|
||||
} else if f.pools != nil {
|
||||
return json.Marshal(f.pools)
|
||||
}
|
||||
}
|
||||
return nil, errors.New("unexpected config state")
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements encoding/json.Unmarshaler.UnmarshalJSON
|
||||
func (f *FakeDNSConfig) UnmarshalJSON(data []byte) error {
|
||||
var pool FakeDNSPoolElementConfig
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue