2015-10-30 10:56:46 -04:00
|
|
|
package net
|
|
|
|
|
2016-01-15 08:34:33 -05:00
|
|
|
import (
|
2016-05-24 16:41:51 -04:00
|
|
|
"strings"
|
2016-01-15 08:34:33 -05:00
|
|
|
)
|
|
|
|
|
2016-09-20 04:44:44 -04:00
|
|
|
func ParseNetwork(nwStr string) Network {
|
|
|
|
if network, found := Network_value[nwStr]; found {
|
|
|
|
return Network(network)
|
|
|
|
}
|
|
|
|
switch strings.ToLower(nwStr) {
|
|
|
|
case "tcp":
|
|
|
|
return Network_TCP
|
|
|
|
case "udp":
|
|
|
|
return Network_UDP
|
|
|
|
default:
|
|
|
|
return Network_Unknown
|
|
|
|
}
|
|
|
|
}
|
2015-10-30 10:56:46 -04:00
|
|
|
|
2017-08-22 09:15:09 -04:00
|
|
|
func (n Network) AsList() *NetworkList {
|
2016-09-22 06:14:50 -04:00
|
|
|
return &NetworkList{
|
2017-08-22 09:15:09 -04:00
|
|
|
Network: []Network{n},
|
2016-09-22 06:14:50 -04:00
|
|
|
}
|
2016-01-17 10:20:49 -05:00
|
|
|
}
|
|
|
|
|
2017-08-22 09:15:09 -04:00
|
|
|
func (n Network) SystemString() string {
|
|
|
|
switch n {
|
2017-01-03 08:53:59 -05:00
|
|
|
case Network_TCP:
|
2016-09-20 04:44:44 -04:00
|
|
|
return "tcp"
|
2017-01-12 06:54:34 -05:00
|
|
|
case Network_UDP:
|
2016-09-20 04:44:44 -04:00
|
|
|
return "udp"
|
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
2016-06-03 18:38:22 -04:00
|
|
|
}
|
|
|
|
|
2017-08-22 09:15:09 -04:00
|
|
|
func (n Network) URLPrefix() string {
|
|
|
|
switch n {
|
2017-01-03 08:53:59 -05:00
|
|
|
case Network_TCP:
|
2016-09-20 05:53:05 -04:00
|
|
|
return "tcp"
|
|
|
|
case Network_UDP:
|
|
|
|
return "udp"
|
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 11:51:01 -04:00
|
|
|
func HasNetwork(list []Network, network Network) bool {
|
|
|
|
for _, value := range list {
|
|
|
|
if string(value) == string(network) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-02-20 05:25:05 -05:00
|
|
|
// HasNetwork returns true if the given network is in v NetworkList.
|
2017-08-22 09:15:09 -04:00
|
|
|
func (l NetworkList) HasNetwork(network Network) bool {
|
|
|
|
for _, value := range l.Network {
|
2016-01-15 08:34:33 -05:00
|
|
|
if string(value) == string(network) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2015-10-30 10:56:46 -04:00
|
|
|
}
|
2016-10-02 17:43:58 -04:00
|
|
|
|
2017-08-22 09:15:09 -04:00
|
|
|
func (l NetworkList) Get(idx int) Network {
|
|
|
|
return l.Network[idx]
|
2016-10-02 17:43:58 -04:00
|
|
|
}
|
2017-01-05 05:20:04 -05:00
|
|
|
|
2017-02-20 05:25:05 -05:00
|
|
|
// Size returns the number of networks in this network list.
|
2017-08-22 09:15:09 -04:00
|
|
|
func (l NetworkList) Size() int {
|
|
|
|
return len(l.Network)
|
2017-01-05 05:20:04 -05:00
|
|
|
}
|