go: net/url: first path segment in URL cannot contain colon.
Description:
No Scheme, and the address format is ”IP: Port“ Address parsing failed.
OS Ver:
Mac OSX 10.12.3
Go Ver:
1.8
Go ENV:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/shibingli/Develop/Go_Code/webconsole"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dy/lsbr_78131x3s9fjq15v8rg80000gn/T/go-build052845002=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
Code:
u, err := url.Parse("192.168.2.2:6688")
if nil != err {
panic(err)
}
fmt.Println(u.Host, u.Port())
Error:
panic: parse 192.168.2.2:6688: first path segment in URL cannot contain colon
goroutine 1 [running]:
main.main()
/Users/shibingli/Develop/Go_Code/webconsole/src/apibox.club/test/test.go:46 +0x138
Source:
https://github.com/golang/go/blob/release-branch.go1.8/src/net/url/url.go#L513
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (8 by maintainers)
Commits related to this issue
- Fixes breaking change done in net/url A change made to the net/url library in go 1.8 causes a panic when starting kontrol: panic: parse 127.0.0.1:4001: first path segment in URL cannot contain colon... — committed to eikaas/kite by eikaas 7 years ago
- oauth2_proxy: default address updated Go will fail to parse this otherwise. https://github.com/golang/go/issues/19297 — committed to dmjio/nixpkgs by dmjio 7 years ago
Closing as working-as-intended. It could be documented better. That is #18824. But @mattn is right. The correct way is
//192.168.1.2:44. Read #18824 for details.