is /. and / same in go? Period(.) as id is not recognised

58 Views Asked by At

I have two route handlers

v1Router. Path("/{id}"). Methods(http.MethodGet). Handler(r.getter())

v1Router. Path("/"). Methods(http.MethodGet). Handler(r.searcher())

when i am sending request at /"some id" it is working as expected ,but when i am sending request at /. the request is going through second handler.

Can anyone explain the above behaviour?

when i am sending request at /"some id" it is working as expected ,but when i am sending request at /. the request is going through second handler.

2

There are 2 best solutions below

1
Volker On

is /. and / same in go?

No, they aren't. Especially not as an URL path.

0
coxley On

It's mentioned in the documentation for the net/http package, underneath http.ServeMux — though it's easy to miss.

Ref: https://pkg.go.dev/net/http#hdr-Request_sanitizing

Source: https://go.dev/src/net/http/server.go?s=40985:41006#L2450

Single and double periods are stripped from the route.