3 ZH_Params
Lunny Xiao edited this page 4 years ago
  • Params Params让你能够获得路由匹配的参数。对于命名路由:
type Action struct {
    tango.Params
}
func (a *Action) Get() string {
    return a.Params.Get(":name")
}

func main() {
    t := tango.Classic()
    t.Get("/:name", new(Action))
    t.Run()
}

对于正则路由,也通过:name来获得

type Action struct {
    tango.Params
}
func (a *Action) Get() string {
    return a.Params.Get(":name")
}

func main() {
    t := tango.Classic()
    t.Post("/(:name.*)", new(Action))
    t.Run()
}