Closed
Description
Go version
1.22.0
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/matteo/Library/Caches/go-build'
GOENV='/Users/matteo/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/matteo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/matteo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/Cellar/go/1.22.0/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/Cellar/go/1.22.0/libexec/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/tb/wk8169j96gbcyz_jrppmchvm0000gn/T/go-build2446679495=/tmp/go-build -gno-record-gcc-switches -fno-common'
What did you do?
With the new routing style in go 1.22, declaring
http.Handle("GET /", h)
generates a conflict with route "/debug/vars" declared in the expvar package.
What did you see happen?
panic: pattern "GET /" (registered at ...) conflicts with pattern "/debug/vars" (registered at ...expvar.go:384):
GET / matches fewer methods than /debug/vars, but has a more general path pattern
What did you expect to see?
No error.
It can be fixed with this patch
--- a/src/expvar/expvar.go
+++ b/src/expvar/expvar.go
@@ -381,7 +381,7 @@ func memstats() any {
}
func init() {
- http.HandleFunc("/debug/vars", expvarHandler)
+ http.HandleFunc("GET /debug/vars", expvarHandler)
Publish("cmdline", Func(cmdline))
Publish("memstats", Func(memstats))
}