ThinkGo 是一個(gè)輕量級(jí)的 Go 語(yǔ)言 MVC 框架,目前支持路由、中間件、控制器、請(qǐng)求、響應(yīng)、Session、視圖、日志、緩存、ORM等 web 框架應(yīng)該具備的基本功能,ThinkGo致力于讓代碼簡(jiǎn)潔且富于表達(dá)力,幫助開發(fā)者快速構(gòu)建一個(gè) Web 應(yīng)用。
特性
- 簡(jiǎn)潔的路由,支持參數(shù)注入
- 強(qiáng)大的路由中間件,支持
前置/后置中間件 - Session支持,支持cookie、redis及自定義存儲(chǔ)
- 強(qiáng)大的日志服務(wù),支持多通道存儲(chǔ),遵循
RFC 5424規(guī)范。 - 緩存,支持memory、redis及自定義緩存驅(qū)動(dòng)
- 簡(jiǎn)潔的ORM,能使用原生 SQL、流暢的查詢構(gòu)造器
安裝
go get github.com/forgoer/thinkgo
快速開始
package main
import (
"github.com/forgoer/thinkgo"
"fmt"
"github.com/forgoer/thinkgo/router"
"github.com/forgoer/thinkgo/context"
)
func main() {
app := thinkgo.BootStrap()
app.RegisterRoute(func(route *router.Route) {
route.Get("/", func(req *context.Request) *context.Response {
return thinkgo.Text("Hello ThinkGo !")
})
route.Get("/ping", func(req *context.Request) *context.Response {
return thinkgo.Json(map[string]string{
"message": "pong",
})
})
// Dependency injection
route.Get("/user/{name}", func(req *context.Request, name string) *context.Response {
return thinkgo.Text(fmt.Sprintf("Hello %s !", name))
})
})
// listen and serve on 0.0.0.0:9011
app.Run()
}
協(xié)議
ThinkGo 采用 Apache 2.0 開源協(xié)議發(fā)布。