WeMVC - Go MVC框架


Apache
跨平台
Google Go

软件简介

WeMVC是一个用go语言开发的简单的高性能MVC框架。它有以下特色:

  1. 全新的路由算法,性能超棒。支持路由变量自定义验证(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”).

  2. 特有的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();

  3. View借鉴beego框架处理方式,将View编译缓存到内存,实时监控view文件的变化,提高View渲染性能;
  4. 友好的WebAPI处理,支持多种输出格式JSON,XML, JSONP等
  5. 支持Session
  6. 支持Filter
  7. 支持Cache
  8. 支持Area
  9. 支持自定义错误(如404)处理
  10. 自动监视文件改动,当配置文件改动之后自动加载到服务器中

示例:

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