Description
Go version
go version go1.22.1 windows/amd64
Output of go env
in your module/workspace:
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\victo\AppData\Local\go-build
set GOENV=C:\Users\victo\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\victo\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\victo\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\victo\personal-projects\enhance-rewrite\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\victo\AppData\Local\Temp\go-build3178868854=/tmp/go-build -gno-record-gcc-switches
What did you do?
I decided to try the new http.ServeMux
but it seems the pattern matching behaves inconsistently across operating systems. Basically my route never gets matched and a 404 gets returned, even though the request has the exact same method and path as the one configured for the route.
I am developing on a Windows 10 machine but when I try the same code on a Linux machine I get a different result. I don't have a Linux machine at hand so I ran the code on the Go playground, which I'm assuming is running on Linux servers (a quick loop of os.Environ()
in Go playground also suggests this).
Here's a small example to demonstrate the problem.
package main
import (
"log"
"net/http"
"net/url"
)
func main() {
mux := http.NewServeMux()
h := func(w http.ResponseWriter, r *http.Request) {}
mux.HandleFunc("GET /some/path", h)
r := &http.Request{
Method: "GET",
URL: &url.URL{Path: "/some/path"},
}
_, pattern := mux.Handler(r)
log.Printf("pattern: \"%s\"\n", pattern)
}
What did you see happen?
I get the following output.
$ pattern: ""
I want to emphasize again that this seems to happen only on Windows.
What did you expect to see?
I expected the following output.
$ pattern: "GET /some/path"
I get this output only in Go playground which I'm assuming is running Linux.