WeMVCGo MVC框架
WeMVC是一個(gè)用go語(yǔ)言開(kāi)發(fā)的簡(jiǎn)單的高性能MVC框架。它有以下特色:
- 全新的路由算法,性能超棒。支持路由變量自定義驗(yàn)證(route parameter validation),支持默值設(shè)置。示例:
wemvc.Route("/blog/<year:int(4)>-<month:int(1~2)>-<day:int(1~2)>/<title>", blogController{}) wemvc.Route("/test/<company>/<uid:int>/<department=admin>/<title=manager>", TestController{}, "Route_Data"). - 特有的Action處理方式:Action方法名的處理采用[Http Method]+[Action Name]方式。例如程序中有個(gè)路由規(guī)則wemvc.Route("/user/<action>", User{})。當(dāng)以GET方式訪問(wèn)http://localhost:8080/user/login時(shí),路由器捕捉到HttpMethod是Get,Action是login,所以執(zhí)行的方法是GetLogin()。而當(dāng)POST提交表單時(shí),路由器捕捉到HttpMethod是Post,Action是login,然后執(zhí)行方法PostLogin()。如果無(wú)法找到GetLogin或PostLogin,則執(zhí)行方法Login();
- View借鑒beego框架處理方式,將View編譯緩存到內(nèi)存,實(shí)時(shí)監(jiān)控view文件的變化,提高View渲染性能;
- 友好的WebAPI處理,支持多種輸出格式JSON,XML, JSONP等
- 支持Session
- 支持Filter
- 支持Cache
- 支持Area
- 支持自定義錯(cuò)誤(如404)處理
- 自動(dòng)監(jiān)視文件改動(dòng),當(dāng)配置文件改動(dòng)之后自動(dòng)加載到服務(wù)器中
示例:
package main
import "github.com/Simbory/wemvc"
type HomeController struct {
wemvc.Controller
}
func (this HomeController) Index() wemvc.ActionResult {
return this.Content("hello world!<br/><a href=\"/about\">About</a>", "text/html")
}
func (this HomeController) GetAbout() wemvc.ActionResult {
obj := make(map[string]interface{})
obj["routeData"] = this.RouteData
obj["headers"] = this.Request.Header
return this.Json(obj)
}
func init() {
wemvc.Route("/", HomeController{})
wemvc.Route("/<action>", HomeController{})
}
func main() {
wemvc.Run(8080);
}
另一個(gè)更加完整的的示例:
https://github.com/Simbory/wemvc-sample
評(píng)論
圖片
表情
