diff --git a/common/collect/string_list.go b/common/collect/string_list.go deleted file mode 100644 index 528c213e94..0000000000 --- a/common/collect/string_list.go +++ /dev/null @@ -1,12 +0,0 @@ -package collect - -type StringList []string - -func NewStringList(raw []string) *StringList { - list := StringList(raw) - return &list -} - -func (this StringList) Len() int { - return len(this) -} diff --git a/common/collect/string_list_json.go b/common/collect/string_list_json.go deleted file mode 100644 index 0233bef2d4..0000000000 --- a/common/collect/string_list_json.go +++ /dev/null @@ -1,25 +0,0 @@ -// +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)) -} diff --git a/common/collect/string_list_json_test.go b/common/collect/string_list_json_test.go deleted file mode 100644 index 82b02aac1d..0000000000 --- a/common/collect/string_list_json_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build json - -package collect_test - -import ( - "encoding/json" - "testing" - - . "v2ray.com/core/common/collect" - "v2ray.com/core/testing/assert" -) - -func TestStringListUnmarshalError(t *testing.T) { - assert := assert.On(t) - - rawJson := `1234` - list := new(StringList) - err := json.Unmarshal([]byte(rawJson), list) - assert.Error(err).IsNotNil() -} - -func TestStringListLen(t *testing.T) { - assert := assert.On(t) - - rawJson := `"a, b, c, d"` - list := new(StringList) - err := json.Unmarshal([]byte(rawJson), list) - assert.Error(err).IsNil() - assert.Int(list.Len()).Equals(4) -} diff --git a/common/net/network.go b/common/net/network.go index 8d13c23304..4afd615443 100644 --- a/common/net/network.go +++ b/common/net/network.go @@ -2,8 +2,6 @@ package net import ( "strings" - - "v2ray.com/core/common/collect" ) func ParseNetwork(nwStr string) Network { @@ -56,17 +54,6 @@ func (this Network) UrlPrefix() string { } } -// NewNetworkList construsts a NetWorklist from the given StringListeralList. -func NewNetworkList(networks collect.StringList) *NetworkList { - list := &NetworkList{ - Network: make([]Network, networks.Len()), - } - for idx, network := range networks { - list.Network[idx] = ParseNetwork(network) - } - return list -} - // HashNetwork returns true if the given network is in this NetworkList. func (this NetworkList) HasNetwork(network Network) bool { for _, value := range this.Network { diff --git a/common/net/network_json.go b/common/net/network_json.go deleted file mode 100644 index 93e9947653..0000000000 --- a/common/net/network_json.go +++ /dev/null @@ -1,27 +0,0 @@ -// +build json - -package net - -import ( - "encoding/json" - - "v2ray.com/core/common/collect" -) - -func (this *Network) UnmarshalJSON(data []byte) error { - var str string - if err := json.Unmarshal(data, &str); err != nil { - return err - } - *this = ParseNetwork(str) - return nil -} - -func (this *NetworkList) UnmarshalJSON(data []byte) error { - var strlist collect.StringList - if err := json.Unmarshal(data, &strlist); err != nil { - return err - } - *this = *NewNetworkList(strlist) - return nil -} diff --git a/common/net/network_json_test.go b/common/net/network_json_test.go deleted file mode 100644 index 2bcbd6ecb9..0000000000 --- a/common/net/network_json_test.go +++ /dev/null @@ -1,48 +0,0 @@ -// +build json - -package net_test - -import ( - "encoding/json" - "testing" - - . "v2ray.com/core/common/net" - "v2ray.com/core/testing/assert" -) - -func TestStringNetwork(t *testing.T) { - assert := assert.On(t) - - var network Network - err := json.Unmarshal([]byte(`"tcp"`), &network) - assert.Error(err).IsNil() - assert.Bool(network == Network_TCP).IsTrue() -} - -func TestArrayNetworkList(t *testing.T) { - assert := assert.On(t) - - var list NetworkList - err := json.Unmarshal([]byte("[\"Tcp\"]"), &list) - assert.Error(err).IsNil() - assert.Bool(list.HasNetwork(ParseNetwork("tcp"))).IsTrue() - assert.Bool(list.HasNetwork(ParseNetwork("udp"))).IsFalse() -} - -func TestStringNetworkList(t *testing.T) { - assert := assert.On(t) - - var list NetworkList - err := json.Unmarshal([]byte("\"TCP, ip\""), &list) - assert.Error(err).IsNil() - assert.Bool(list.HasNetwork(ParseNetwork("tcp"))).IsTrue() - assert.Bool(list.HasNetwork(ParseNetwork("udp"))).IsFalse() -} - -func TestInvalidNetworkJson(t *testing.T) { - assert := assert.On(t) - - var list NetworkList - err := json.Unmarshal([]byte("0"), &list) - assert.Error(err).IsNotNil() -}