Go 的全棧 Web 框架,Revel v0.12.0 發布
Revel 是 Go 語言的框架,其思路完全來自 Java 的 Play Framework。
Features
Hot Code Reload
Edit, save, and refresh. Revel compiles your code and templates for you, so you don't miss a beat. Code doesn't compile? It gives you a helpful description. Run-time code panic? Revel has you covered.
Comprehensive
Revel provides routing, parameter parsing, validation, session/flash, templating, caching, job running, a testing framework, and even internationalization.
High Performance
Revel builds on top of the Go HTTP server, which was recently benchmarked to serve three to ten times as many requests as Rails across a variety of loads.
testing 子包 :
package tests
import "github.com/revel/revel/testing"
type AppTest struct {
testing.TestSuite
} 同時還改進了內部組織結構,更多內容請看發行說明。
此版本現已提供下載:https://github.com/revel/revel/archive/v0.12.0.zip。
控制器示例:
// app/controllers/app.go
type Application struct {
*rev.Controller
}
func (c Application) Register() rev.Result {
title := "Register"
return c.Render(title)
}
func (c Application) SaveUser(user models.User, verifyPassword string) rev.Result {
c.Validation.Required(verifyPassword).Key("verifyPassword")
c.Validation.Required(verifyPassword == user.Password).Key("verifyPassword").
Message("Password does not match")
user.Validate(c.Validation)
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
return c.Redirect(Application.Register)
}
_, err := c.Txn.Exec("insert into User (Username, Password, Name) values (?, ?, ?)",
user.Username, user.Password, user.Name)
if err != nil {
panic(err)
}
c.Session["user"] = user.Username
c.Flash.Success("Welcome, " + user.Name)
return c.Redirect(Hotels.Index)
}