Skip to content
This repository has been archived by the owner on Nov 17, 2019. It is now read-only.

Latest commit

 

History

History
60 lines (52 loc) · 1.04 KB

2-router-body.md

File metadata and controls

60 lines (52 loc) · 1.04 KB

Execute body

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()

func()

t := tango.Classic()
t.Get("/", func() string {
    return "hello tango"
})

func(http.ResponseWriter, *http.Request)

t := tango.Classic()
t.Post("/", func(w http.ResponseWriter, *http.Request) {
    w.Write([]byte("hello tango"))
})

func(http.ResponseWriter)

t := tango.Classic()
t.Post("/", func(w http.ResponseWriter) {
    w.Write([]byte("hello tango"))
})

func(*http.Request)

t := tango.Classic()
t.Post("/", func(req *http.Request) string {
    return req.FormValue("key")
})

func(*tango.Context)

t := tango.Classic()
t.Get("/:name", func(ctx *tango.Context) {
    ctx.Write([]byte("hello " + ctx.Params().Get(":name")))
})

structs

type Action struct {}
func (a *Action) Get() string {
    return "haha"
}
t := tango.Classic()
t.Get("/:name", new(Action))