返回值


    • 返回string,将会把string转为[]byte同时写入到ResponseWriter

    • []byte
      返回[]byte将会直接写入ResponseWriter

    • AbortError
      如果返回AbortError, 则写入返回头AbortError.Code,内容为AbortError.Error()

    如果包含了匿名结构体 tango.JSON 或者 tango.XML,则返回值的行为将会发生变化:

    • map, , structs
      返回值为map,如果是Json,则会自动序列化为Json格式。

    例子代码如下:

    1. type Action struct {
    2. }
    3. var i int
    4. func (Action) Get() (int, interface{}) {
    5. if i == 0 {
    6. return 200, map[string]interface{}{"i":i}
    7. return 500, errors.New("could not visit")
    8. }
    9. func main() {
    10. t := tango.Classic()
    11. t.Any("/", new(Action))