Go 的全棧 Web 框架,Revel v0.11.2 發布

jopen 10年前發布 | 8K 次閱讀 Revel

Revel 是一個Go 語言高效的,全棧Web開發框架,靈感源于Rails 和 Play!。

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.

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.

Synchronous

The Go HTTP server runs each request in its own goroutine. Write simple callback-free code without guilt.

Stateless

Revel provides primitives that keep the web tier stateless for predictable scaling. For example, session data is stored in the user cookie, and the cache is backed by a memcached cluster.

Modular

Revel is built around composable middleware called filters, which implement nearly all request-processing functionality. Developers have the freedom to replace the default filters with custom implementations (e.g. a custom router).

          

Revel v0.11.2 發布,此版本修復了一個重要的 bug,強烈建議每位用戶用最新的 Revel 版本重建項目,升級請執行:

$ go get -u github.com/revel/cmd/revel

$ revel build github.com/myusername/myproject /path/to/destination/folder

此版本現已提供下載

 

// 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)
}
 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!