Config: Correctly marshal Int32Range to JSON (#4234)

Fixes https://github.com/XTLS/libXray/issues/62
This commit is contained in:
yiguous 2025-01-01 18:16:36 +08:00 committed by RPRX
parent 8a6a5385ff
commit 480eac7235

View File

@ -2,6 +2,7 @@ package conf
import (
"encoding/json"
"fmt"
"strconv"
"strings"
@ -258,6 +259,18 @@ type Int32Range struct {
To int32
}
func (v Int32Range) MarshalJSON() ([]byte, error) {
return json.Marshal(v.String())
}
func (v Int32Range) String() string {
if v.Left == v.Right {
return strconv.Itoa(int(v.Left))
} else {
return fmt.Sprintf("%d-%d", v.Left, v.Right)
}
}
func (v *Int32Range) UnmarshalJSON(data []byte) error {
defer v.ensureOrder()
var str string