summaryrefslogtreecommitdiff
path: root/types/net_type.go
blob: ce82288581072b3f6ab61b2125d143b5b60a2445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package types

import "fmt"

type IpNetType string

var (
	IPv6Net IpNetType = "ipv6"
	IPv4Net IpNetType = "ipv4"
	IP64    IpNetType = "any"
)

// GetDialNetString returns the string accepted by net.Dialer::DialContext
func (t IpNetType) GetDialNetString() string {
	switch t {
	case IPv4Net:
		return "tcp4"
	case IPv6Net:
		return "tcp6"
	case IP64:
		return "tcp"
	}
	return ""
}

func (t IpNetType) String() string {
	return fmt.Sprintf("%s(%s)", string(t), t.GetDialNetString())
}