yarf
yarf copied to clipboard
url with tailling flash /hello/aa/ match route "/hello/:name" should return 404 like net/http
package main
import "github.com/yarf-framework/yarf"
type Hello struct {
yarf.Resource
}
func (h *Hello) Get(c *yarf.Context) error {
name := c.Param("name")
c.Render("Hello, " + name)
return nil
}
func main() {
// Create a new empty YARF server
y := yarf.New()
hello := new(Hello)
y.Add("/", hello)
y.Add("/hello/:name", hello)
y.Start(":8080")
}
$ curl http://localhost:8080/hello/xxx/ Hello, xxx
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/hello/xxx", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to my website!")
})
http.ListenAndServe(":80", nil)
}
curl http://localhost:8080/hello/xxx/ Not found
Hi @tablecell ,
The trailing slash behaviour is made on purpose here. As described in the README doc in the "Simple router" section. The implementation code is also clear about that purpose.
That said, other than what net/http does, is there other arguments to discuss about this? I'm open to review the design.