mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
Config: Correctly marshal PortList and NameServerConfig to JSON (#4386)
This commit is contained in:
parent
a71762b5da
commit
94c7970fd6
2 changed files with 25 additions and 7 deletions
|
@ -203,6 +203,24 @@ func (list *PortList) Build() *net.PortList {
|
|||
return portList
|
||||
}
|
||||
|
||||
func (v PortList) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(v.String())
|
||||
}
|
||||
|
||||
func (v PortList) String() string {
|
||||
ports := []string{}
|
||||
for _, port := range v.Range {
|
||||
if port.From == port.To {
|
||||
p := strconv.Itoa(int(port.From))
|
||||
ports = append(ports, p)
|
||||
} else {
|
||||
p := fmt.Sprintf("%d-%d", port.From, port.To)
|
||||
ports = append(ports, p)
|
||||
}
|
||||
}
|
||||
return strings.Join(ports, ",")
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements encoding/json.Unmarshaler.UnmarshalJSON
|
||||
func (list *PortList) UnmarshalJSON(data []byte) error {
|
||||
var listStr string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue