network.go 857 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package net
  2. func (n Network) AsList() *NetworkList {
  3. return &NetworkList{
  4. Network: []Network{n},
  5. }
  6. }
  7. func (n Network) SystemString() string {
  8. switch n {
  9. case Network_TCP:
  10. return "tcp"
  11. case Network_UDP:
  12. return "udp"
  13. default:
  14. return "unknown"
  15. }
  16. }
  17. func HasNetwork(list []Network, network Network) bool {
  18. for _, value := range list {
  19. if string(value) == string(network) {
  20. return true
  21. }
  22. }
  23. return false
  24. }
  25. // HasNetwork returns true if the given network is in v NetworkList.
  26. func (l NetworkList) HasNetwork(network Network) bool {
  27. for _, value := range l.Network {
  28. if string(value) == string(network) {
  29. return true
  30. }
  31. }
  32. return false
  33. }
  34. func (l NetworkList) Get(idx int) Network {
  35. return l.Network[idx]
  36. }
  37. // Size returns the number of networks in this network list.
  38. func (l NetworkList) Size() int {
  39. return len(l.Network)
  40. }