Description
Go version
go1.24.4 darwin/arm64
Output of go env
in your module/workspace:
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/apple/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/apple/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/3q/y8p6ypf54rj5wygqz4kymqt00000gn/T/go-build4086332495=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/apple/GolandProjects/pdf_service_api/go.mod'
GOMODCACHE='/Users/apple/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/apple/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/apple/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.4'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Passing Host=localhost Port=60627 user=user Password=password dbname=postgres sslmode=disable
as the second parameter in db, err := sql.Open("postgres", str)
Line 863 in 54c9d77
What did you see happen?

despite being passed to the sql.Open function with a dynamic port of 60627, the default port overrides the port being passed, due to a malformed dataSourceName without any warning being given, or error being thrown (Except: dial tcp [::1]:5432: connect: connection refused, due to the wrong port being used.)
The fix was to pass a url style string: postgres://user:password@localhost:60627/postgres?sslmode=disable, which corrected the wrong port being used.
What did you expect to see?
I expected port 60627 to be used instead of 5432 after passing a connection string that specified a different port, there was no indication that this was happening, and no error thrown by Sql.Open.