Tango 操作手册
Go to file
2019-11-27 20:46:46 +08:00
chapter-01 update import path 2019-11-27 20:46:46 +08:00
chapter-02 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-03 import all documents from wiki 2016-02-01 16:49:12 +08:00
chapter-04 change Json to JSON since Json deprecated 2017-04-11 14:41:25 +08:00
chapter-05 update import path 2019-11-27 20:46:46 +08:00
chapter-06 import all documents from wiki 2016-02-01 16:49:12 +08:00
chapter-07 change Json to JSON since Json deprecated 2017-04-11 14:41:25 +08:00
chapter-08 import all documents from wiki 2016-02-01 16:49:12 +08:00
chapter-09 update import path 2019-11-27 20:46:46 +08:00
chapter-10 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-11 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-12 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-13 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-14 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-15 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-16 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-17 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-18 update import path 2019-11-27 20:46:46 +08:00
chapter-19 Change to new gitea address 2019-11-17 16:17:05 +08:00
chapter-20 import all documents from wiki 2016-02-01 16:49:12 +08:00
chapter-21 import all documents from wiki 2016-02-01 16:49:12 +08:00
chapter-22 import all documents from wiki 2016-02-01 16:49:12 +08:00
.gitignore 初始化 2015-05-20 23:04:48 +08:00
book.json added logo and chapter 01 2016-02-01 14:29:27 +08:00
logo.png added logo and chapter 01 2016-02-01 14:29:27 +08:00
README.md Change to new gitea address 2019-11-17 16:17:05 +08:00
SUMMARY.md update import path 2019-11-27 20:46:46 +08:00

Tango

Tango 是一个微内核易扩展的Go语言Web框架他兼有Beego的效率和Martini的中间件设计。

最近更新

  • [2016-2-1] 新增 session-ssdb支持将ssdb作为session的后端存储
  • [2015-10-23] 更新renders插件,解决模板修改后需要刷新两次才能生效的问题

简介

安装Tango

go get gitea.com/lunny/tango

一个经典的Tango例子如下

package main

import (
    "errors"
    "gitea.com/lunny/tango"
)

type Action struct {
    tango.JSON
}

func (Action) Get() interface{} {
    if true {
        return map[string]string{
            "say": "Hello tango!",
        }
    }
    return errors.New("something error")
}

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

然后在浏览器访问http://localhost:8000, 将会得到一个json返回

{"say":"Hello tango!"}

如果将上述例子中的 true 改为 false, 将会得到一个json返回

{"err":"something error"}

这段代码因为拥有一个内嵌的tango.JSON所以返回值会被自动的转成Json。具体返回可以参见以下文档。

特性

  • 强大而灵活的路由设计
  • 兼容已有的http.Handler
  • 模块化设计,可以很容易写出自己的中间件
  • 高性能的依赖注入方式

中间件

中间件让你像AOP编程那样来操作你的Controller。

目前已有很多 中间件 - gitea.com/tango,可以帮助你快速完成工作:

  • recovery - recover after panic
  • compress - Gzip & Deflate compression
  • static - Serves static files
  • logger - Log the request & inject Logger to action struct
  • param - get the router parameters
  • return - Handle the returned value smartlly
  • context - Inject context to action struct
  • session - Build Status Session manager
  • xsrf - Build Status Generates and validates csrf tokens
  • binding - Build Status Bind and validates forms
  • renders - Build Status Go template engine
  • dispatch - Build Status Multiple Application support on one server
  • tpongo2 - Build Status Pongo2 teamplte engine support
  • captcha - Build Status Captcha
  • events - Build Status Before and After
  • flash - Build Status Share data between requests
  • debug - Build Status show detail debug infomaton on log
  • basicauth - Build Status basicauth middleware

获得帮助

案例