url /user/ match "/user/:id"
Closed this issue · 2 comments
tablecell commented
app.Get("/user/:id", func(c *baa.Context) {
c.String(200, " user id is: " + c.Param("id"))
})
hengfeiyang commented
if you want match the lash slash, please use
app.SetAutoTrailingSlash(true)
please view document:
https://github.com/go-baa/doc/blob/master/zh-CN/router.md#路由选项
tablecell commented
@safeie
app.SetAutoTrailingSlash(true)
[log] GET /user/100/ 200 0s
[log] GET /user/100 200 0s
[log] GET /user/ 200 0s
app.SetAutoTrailingSlash(false)
[log] GET /user/ 200 0s
[log] GET /user/100 200 0s
[log] GET /user/100/ 404 0s
expect like net/http
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/user/100", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to my website!")
})
http.ListenAndServe(":80", nil)
}
$curl http://localhost:80/user/
404 page not found
$ curl http://localhost:80/user/100
Welcome to my website!
$ curl http://localhost:80/user/100/
404 page not found