Skip to content

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

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

Closed
tensorchen opened this issue Oct 30, 2019 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@tensorchen
Copy link

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
Copy link
Contributor

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

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 5, 2019
@tensorchen
Copy link
Author

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
Copy link
Contributor

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

@agnivade agnivade added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Nov 11, 2019
@golang golang locked and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants