net/http: 1.22.0, Enhanced routing, httpmuxgo121

101 views
Skip to first unread message

xab3r

unread,
Feb 11, 2024, 10:47:31 PMFeb 11
to golang-nuts
Hello there

I've just tried new routing patterns in Go 1.22.0, and I noticed that I have to set httpmuxgo121=0 explicitly in order to get it enabled. When the release notes say to "set httpmuxgo121=1 to restore the old behaviour". So, as I understand it, by default, it should work with new path patterns.

This is the handler
```
mux.HandleFunc("GET /hello", func(w http.ResponseWriter, r *http.Request) {
  fmt.Fprint(w, "Hello")
})
```

So this piece of code is not gonna work if I run it like this
`$ go run main.go`
The server responds with 404.

But it's working as expected when I explicitly set httpmuxgo121 to 0
`$ GODEBUG=httpmuxgo121=0 go run main.go`

Also, I compiled go from sources with extra logs and `use121` variable 
is set to 1 by default, when I don't specify it explicitly via the ENV variable.

What's the correct behaviour? Any clues are welcome

Thanks

qiulaidongfeng

unread,
Feb 12, 2024, 2:09:38 AMFeb 12
to golang-nuts
Starting with go1.21, GODEBUG is set by default according to the go line of go.mod.

qiulaidongfeng

unread,
Feb 12, 2024, 2:35:36 AMFeb 12
to golang-nuts
If you want to default GODEBUG=httpmuxgo121=0.
One way to do this is to set go1.22.0 on the go line of go.mod, or add a //go:debug httpmuxgo121=0 to the go file of the main package.
Reply all
Reply to author
Forward
0 new messages