Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url /user/ match "/user/:id" #5

Closed
tablecell opened this issue Aug 19, 2021 · 2 comments
Closed

url /user/ match "/user/:id" #5

tablecell opened this issue Aug 19, 2021 · 2 comments

Comments

@tablecell
Copy link

    app.Get("/user/:id", func(c *baa.Context) {
		c.String(200, "  user id is: " + c.Param("id"))
	})

@hengfeiyang
Copy link
Member

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
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants