5.6 KiB
5.6 KiB
Tango English
Tango 是一个微内核易扩展的Go语言Web框架.
当前版本: v0.2.8 版本更新记录
简介
安装Tango:
go get github.com/lunny/tango
最简单的例子:
package main
import "github.com/lunny/tango"
func main() {
t := tango.Classic()
t.Get("/", func() string {
return "Hello tango!"
})
t.Run()
}
然后在浏览器访问http://localhost:8000
即可。当然了,tango其实对struct形式的支持更好。比如:
package main
import "github.com/lunny/tango"
type Action struct {
tango.Json
}
func (Action) Get() map[string]string {
return map[string]string{
"say": "Hello tango!",
}
}
func main() {
t := tango.Classic()
t.Get("/", new(Action))
t.Run()
}
这段代码因为拥有一个内嵌的tango.Json
,所以返回值会被自动的转成Json。具体返回可以参见以下文档。
特性
- 强大而灵活的路由设计
- 兼容已有的
http.Handler
- 模块化设计,可以很容易写出自定义插件
- 高性能的依赖注入方式
中间件
中间件让你像切面编程那样来操作你的Controller。
目前已有很多 中间件,可以帮助你来简化工作:
- 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
- request - Inject request to action struct
- response - Inject response to action struct
- session - Session manager
- xsrf - Generates and validates csrf tokens
- binding - Bind and validates forms
- renders - Go template engine
- dispatch - Multiple Application support on one server
- tpongo2 - Pongo2 teamplte engine support
- captcha - Captcha
- events - Before and After
- flash - Share data between requests
- debug - show detail debug infomaton on log
获得帮助
案例
讨论
QQ群:369240307
License
This project is under BSD License. See the LICENSE file for the full license text.