If there is a trailing slash in a pattern then redirects don't work as expected. Take the example server from the documentation, but add a slash to the pattern:
package main
import (
"io"
"net/http"
"github.com/bmizerany/pat"
"log"
)
// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
io.WriteString(w, "hello, "+req.URL.Query().Get(":name")+"!\n")
}
func main() {
m := pat.New()
m.Get("/hello/:name/", http.HandlerFunc(HelloServer))
http.Handle("/", m)
err := http.ListenAndServe(":12345", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
If we request /hello/bob/ everything works as expected:
It looks like the code is using the pattern as the redirect target, instead of the requested url.
The docs on this are also unclear, they say "A pattern ending with a slash will get an implicit redirect to it's non-slash version." - but the redirect appears to be from the non-slash version.
If there is a trailing slash in a pattern then redirects don't work as expected. Take the example server from the documentation, but add a slash to the pattern:
If we request
/hello/bob/
everything works as expected:But if we request a url without a trailing slash like
/hello/bob
we get a broken redirect to/hello/:name/
It looks like the code is using the pattern as the redirect target, instead of the requested url.
The docs on this are also unclear, they say "A pattern ending with a slash will get an implicit redirect to it's non-slash version." - but the redirect appears to be from the non-slash version.