mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
26 lines
511 B
Go
26 lines
511 B
Go
// +build json
|
|
|
|
package collect
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
func (this *StringList) UnmarshalJSON(data []byte) error {
|
|
var strarray []string
|
|
if err := json.Unmarshal(data, &strarray); err == nil {
|
|
*this = *NewStringList(strarray)
|
|
return nil
|
|
}
|
|
|
|
var rawstr string
|
|
if err := json.Unmarshal(data, &rawstr); err == nil {
|
|
strlist := strings.Split(rawstr, ",")
|
|
*this = *NewStringList(strlist)
|
|
return nil
|
|
}
|
|
return errors.New("Unknown format of a string list: " + string(data))
|
|
}
|