network.go 553 B

12345678910111213141516171819202122232425262728293031
  1. package net
  2. import (
  3. "strings"
  4. )
  5. const (
  6. TCPNetwork = Network("tcp")
  7. UDPNetwork = Network("udp")
  8. )
  9. type Network string
  10. type NetworkList []Network
  11. func NewNetworkList(networks []string) NetworkList {
  12. list := NetworkList(make([]Network, len(networks)))
  13. for idx, network := range networks {
  14. list[idx] = Network(strings.ToLower(strings.TrimSpace(network)))
  15. }
  16. return list
  17. }
  18. func (this *NetworkList) HasNetwork(network Network) bool {
  19. for _, value := range *this {
  20. if string(value) == string(network) {
  21. return true
  22. }
  23. }
  24. return false
  25. }