mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-01-09 20:17:17 +03:00
Config: Correctly marshal Int32Range to JSON (#4234)
Fixes https://github.com/XTLS/libXray/issues/62
This commit is contained in:
parent
8a6a5385ff
commit
480eac7235
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user