You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
funcmain(){
typeapplicationstruct{}
func (app*application) routes() *http.ServeMux {
router.HandleFunc("/api/*", func(w http.ResponseWriter, r*http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("200 OK - This is the entrypoint for all api requests"))
})
router.HandleFunc("GET /*", func(w http.ResponseWriter, r*http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("200 OK - This is the react homepage entrypoint/catchall"))
})
//VERSUS THIS FORMAT!!!!!!! WHICH THROWS ERRORrouter.HandleFunc("/api/", func(w http.ResponseWriter, r*http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("200 OK - This is the entrypoint for all api requests"))
})
router.HandleFunc("GET /", func(w http.ResponseWriter, r*http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("200 OK - This is the react homepage entrypoint/catchall"))
})
}
myApp=&application{}
srv:= http.Server{
Addr: cfg.addr,
ErrorLog: app.errorLog,
Handler: app.routes(),
}
srv.ListenAndServe()
defersrv.Close()
}
Sending GET requests to localhost:4055/api/testing
What did you see happen?
When I use the wilcard (*) in the path I don't get a compile error that the specificity of the Method is more specific than the route pattern.
When I exclude the wildcard * and just use "/api/" and "/" OR "/api/{test...}" and "/{test..}" or "/api/{test..}" and "/" I get the error message properly.
I read through the serveMux documentation and it doesn't say anything about not using * in the route pathing or talk about it's usage as a wildcard
Also when using the wildcard routes /api/* and GET /*
The request sent to /api/testing gets routed to the "GET /" handler instead of the "/api/"
I would have thought it would go to the "/api/*" but after reading the documentation technically neither routes are more specific than each other.
What did you expect to see?
I expected for the * wildcard to behave like the {test...} or trailing slash and throw an error due to non specificity.
There is no mention of the * character in the http/net ServeMux Patterns documentation at all whether it should or should not be used.
Either adding a warning to the documentation to not use the * char, treating * as a normal string character, Treating * as a {test...} wildcard, or throwing an error about * properly.
The text was updated successfully, but these errors were encountered:
Nowhere in Go documentation suggests that * is a valid wildcard character for HTTP paths, I don't think it makes sense to try and mention arbitrary syntaxes that we don't support.
Go version
go version go1.22.5 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Sending GET requests to localhost:4055/api/testing
What did you see happen?
When I use the wilcard (*) in the path I don't get a compile error that the specificity of the Method is more specific than the route pattern.
When I exclude the wildcard * and just use "/api/" and "/" OR "/api/{test...}" and "/{test..}" or "/api/{test..}" and "/" I get the error message properly.
I read through the serveMux documentation and it doesn't say anything about not using * in the route pathing or talk about it's usage as a wildcard
Also when using the wildcard routes /api/* and GET /*
The request sent to /api/testing gets routed to the "GET /" handler instead of the "/api/"
I would have thought it would go to the "/api/*" but after reading the documentation technically neither routes are more specific than each other.
What did you expect to see?
I expected for the * wildcard to behave like the {test...} or trailing slash and throw an error due to non specificity.
There is no mention of the * character in the http/net ServeMux Patterns documentation at all whether it should or should not be used.
Either adding a warning to the documentation to not use the * char, treating * as a normal string character, Treating * as a {test...} wildcard, or throwing an error about * properly.
The text was updated successfully, but these errors were encountered: