You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
3 years ago | |
---|---|---|
chapter-01 | 3 years ago | |
chapter-02 | 3 years ago | |
chapter-03 | 7 years ago | |
chapter-04 | 5 years ago | |
chapter-05 | 3 years ago | |
chapter-06 | 7 years ago | |
chapter-07 | 5 years ago | |
chapter-08 | 7 years ago | |
chapter-09 | 3 years ago | |
chapter-10 | 3 years ago | |
chapter-11 | 3 years ago | |
chapter-12 | 3 years ago | |
chapter-13 | 3 years ago | |
chapter-14 | 3 years ago | |
chapter-15 | 3 years ago | |
chapter-16 | 3 years ago | |
chapter-17 | 3 years ago | |
chapter-18 | 3 years ago | |
chapter-19 | 3 years ago | |
chapter-20 | 7 years ago | |
chapter-21 | 7 years ago | |
chapter-22 | 7 years ago | |
.gitignore | 7 years ago | |
README.md | 3 years ago | |
SUMMARY.md | 3 years ago | |
book.json | 7 years ago | |
logo.png | 7 years ago |
README.md
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 -
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
- basicauth -
basicauth middleware