WeMVC是一个用go语言开发的简单的高性能MVC框架。它有以下特色:
全新的路由算法,性能超棒。支持路由变量自定义验证(route parameter validation),支持默值设置。示例:
wemvc.Route("/blog/<year:int(4)>-<month:int(1~2)>-<day:int(1~2)>/<title>", blogController{})
wemvc.Route(“/test////“, TestController{}, “Route_Data”).
特有的Action处理方式:Action方法名的处理采用[Http Method]+[Action Name]方式。例如程序中有个路由规则wemvc.Route(“/user/“, User{})。当以GET方式访问http://localhost:8080/user/login时,路由器捕捉到HttpMethod是Get,Action是login,所以执行的方法是GetLogin()。而当POST提交表单时,路由器捕捉到HttpMethod是Post,Action是login,然后执行方法PostLogin()。如果无法找到GetLogin或PostLogin,则执行方法Login();
示例:
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); }
另一个更加完整的的示例:
https://github.com/Simbory/wemvc-sample