Closed as not planned
Description
Go version
go version go1.24.0 linux/amd64
Output of go env
in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/dazwilkin/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/dazwilkin/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3950176625=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/dazwilkin/[redacted]/test/go.mod'
GOMODCACHE='/home/dazwilkin/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/dazwilkin/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/dazwilkin/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Trying to implement a handler to represent a Google published method:
projects.locations.services.testIamPermissions
POST https://run.googleapis.com/v1/{resource}:testIamPermissions
Where resource=projects/{project}/locations/{location}/services/{service}
There's a limitation of routing enhancements in representing wildcards that contain /
so:
package main
import (
"net/http"
)
func ok(w http.ResponseWriter, _ *http.Request) {
w.Write([]byte("ok"))
}
func main() {
http.HandleFunc("POST /v1/projects/{project}/locations/{location}/services/{service}:testIamPermissions", ok)
http.ListenAndServe(":8080", nil)
}
What did you see happen?
Panics:
panic: parsing "POST /v1/projects/{project}/locations/{location}/services/{service}:testIamPermissions": at offset 58: bad wildcard segment (must end with '}')
goroutine 1 [running]:
net/http.(*ServeMux).register(0xae6d80, {0x8ce82d, 0x56}, {0x8f3000, 0x8d4920})
/usr/local/go/src/net/http/server.go:2872 +0x87
net/http.HandleFunc({0x8ce82d, 0x56}, 0x8d4920)
/usr/local/go/src/net/http/server.go:2866 +0x77
main.main()
/home/dazwilkin/Projects/cloud-run-emulator/test/main.go:12 +0x26
What did you expect to see?
Expected it to succeed.
Removing the :testIamPermissions
succeeds.
If there's no pattern preceding the :method
, it works too (e.g. .../{service}/something:testIamPermissions
I'm using a more general handler that extracts the method and routes accordingly but it would be good if this were supported (documented).
Metadata
Metadata
Assignees
Labels
No labels