Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: why not provide function net.ResolveAddr(network, address string) (net.Addr, error) #35244

Closed
tensorchen opened this issue Oct 30, 2019 · 3 comments

Comments

@tensorchen
Copy link

@tensorchen tensorchen commented Oct 30, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.1 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/niaoge/Library/Caches/go-build"
GOENV="/Users/niaoge/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY="git.code.oa.com"
GONOSUMDB="git.code.oa.com"
GOOS="darwin"
GOPATH="/Users/niaoge/go"
GOPRIVATE="git.code.oa.com"
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/Cellar/go/1.13.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/86/5sbq0ft51h3d1hv9c4g2mfym0000gn/T/go-build337064976=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

	var addr net.Addr
	switch node.Network {
	case "tcp", "tcp4", "tcp6":
		addr, _ = net.ResolveTCPAddr(node.Network, node.Address)
	case "udp", "udp4", "udp6":
		addr, _ = net.ResolveUDPAddr(node.Network, node.Address)
	}
	msg.WithRemoteAddr(addr)

What did you expect to see?

	addr, _ := net.ResolveAddr(node.Network, node.Address)
	msg.WithRemoteAddr(addr)

What did you see instead?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 30, 2019

Can you show us a case where a real program would want that function?

@tensorchen

This comment has been minimized.

Copy link
Author

@tensorchen tensorchen commented Nov 7, 2019

The code involved above is the real code that implements the network framework within my company. This code happens before Dial or ListenPacket, when the network type is unknown, and I need to get net.Addr.

I think the net.ResolveAddr function that returns net.Addr helps users reduce the switch case code, isn't it?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 7, 2019

Thanks, but can you expand on the actual use case? Why is the network type unknown?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.