Tango supports 5 forms functions or struct methods:
- func()
- func(http.ResponseWriter, *http.Request)
- func(*tango.Context)
- func(http.Response.Writer)
- func(*http.Request)
- struct.Get()
t := tango.Classic()
t.Get("/", func() string {
return "hello tango"
})
t := tango.Classic()
t.Post("/", func(w http.ResponseWriter, *http.Request) {
w.Write([]byte("hello tango"))
})
t := tango.Classic()
t.Post("/", func(w http.ResponseWriter) {
w.Write([]byte("hello tango"))
})
t := tango.Classic()
t.Post("/", func(req *http.Request) string {
return req.FormValue("key")
})
t := tango.Classic()
t.Get("/:name", func(ctx *tango.Context) {
ctx.Write([]byte("hello " + ctx.Params().Get(":name")))
})
type Action struct {}
func (a *Action) Get() string {
return "haha"
}
t := tango.Classic()
t.Get("/:name", new(Action))