From f5c63cde56eb35c0125a0545f084441cdd4340ab Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 11 Jul 2023 22:56:07 +0800 Subject: Refactor: move data structures to a separate package to avoid circular dependency. --- types/net_type.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 types/net_type.go (limited to 'types/net_type.go') diff --git a/types/net_type.go b/types/net_type.go new file mode 100644 index 0000000..ce82288 --- /dev/null +++ b/types/net_type.go @@ -0,0 +1,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()) +} -- cgit v1.2.3