コード例 #1
0
ファイル: utils_test.go プロジェクト: xgfone/go-tools
func TestJoinHostPort(t *testing.T) {
	result := "127.0.0.1:8000"

	if nets.JoinHostPort("127.0.0.1", "8000") != result {
		t.Fail()
	}

	if nets.JoinHostPort("127.0.0.1", 8000) != result {
		t.Fail()
	}

	if nets.JoinHostPort([]byte("127.0.0.1"), 8000) != result {
		t.Fail()
	}

	if nets.JoinHostPort([]byte("127.0.0.1"), "8000") != result {
		t.Fail()
	}
}
コード例 #2
0
ファイル: tcp.go プロジェクト: xgfone/go-tools
// DialTCP is the same as DialTCPWithAddr, but it joins host and port firstly.
func DialTCP(host, port interface{}) (*net.TCPConn, error) {
	addr := nets.JoinHostPort(host, port)
	return DialTCPWithAddr(addr)
}