代码改变世界

阅读排行榜

Go Web开发之Revel - 拦截器

2013-01-07 15:18 by Danny.tian, 3353 阅读, 收藏,
摘要: 一个拦截器是一个框架在调用action方法前或后调用的函数. 它允许一种AOP的形式, 它经常被用于做下面几种事情:Request loggingError handlingStats keeping在Revel里, 一个拦截器能接受两种形式:1. 函数拦截器: 一个函数满足InterceptorFunc接口没有访问特定的应用程序Controller被调用在应用程序中可以应用于任意或全部Controller2. 方法拦截器:一个controller的方法接受没有参数和rev.Result的返回值可以只拦截受约束的Controller可以修改被调用的controller作为想得到的拦截器按照被添 阅读全文

Go Web开发之Revel - Session/Flash

2013-01-06 09:55 by Danny.tian, 3317 阅读, 收藏,
摘要: Revel提供两个基于cookie的存储机制.// A signed cookie (and thus limited to 4kb in size).// Restriction: Keys may not have a colon in them.type Session map[string]string// Flash represents a cookie that gets overwritten on each request.// It allows data to be stored across one page at a time.// This is commonly 阅读全文

Go Web开发之Revel - 介绍

2012-12-28 15:53 by Danny.tian, 3287 阅读, 收藏,
摘要: Revel框架的资源如下:Revel的新东东? 概念.Mailing ListSearch our mailing list (revel-framework@googlegroups.com)帮组邮箱Send an email to the revel-framework@googlegroups.comBug提交Open an issue on github. 阅读全文

Go Web开发之Revel - 概念

2012-12-28 15:58 by Danny.tian, 3224 阅读, 收藏,
摘要: MVC摘要:Model:用于描述你的应用程序域的基本数据对象,Model也包含特定领域的逻辑为了查询和更新数据View:描述怎样展示和操作数据Controller:处理请求的执行,他们执行用户期待的Action,他们决定哪个视图将被用于显示,他们还为视图准备和提供必要的数据用于渲染视图每个请求产生一个Goroutine Revel构建于Go HTTP server之上,它为每一个进来的请求创建一个go-routine(轻量级线程),这意味着你的代码可以自由的阻塞,但必须处理并发请求处理。Controllers and Actions 每一个HTTP请求调用一个action,它处理请求和输出.. 阅读全文

Go Web开发之Revel - Hello World

2012-12-28 14:43 by Danny.tian, 3069 阅读, 收藏,
摘要: 下面结合之前创建的myapp做一个提交表单的demo首先编辑app/views/Application/Index.html模板文件添加一下form表单<form action="/Application/Hello" method="GET"> <input type="text" name="myName" /> <input type="submit" value="Say hello!" /></form>刷新表单我们提 阅读全文

Go Web开发之Revel - 验证

2013-01-05 10:24 by Danny.tian, 2643 阅读, 收藏,
摘要: Revel提供内建的函数来验证参数.这里有一对部件:一个验证上下文收集器和消息验证错误(keys和消息)帮助函数检查数据并把错误信息加入上下文一个模板函数从验证上下的key获得错误信息更深入的了解验证可以看一下 示例demo内联错误信息这个示例演示用内联错误信息验证字段.func (c MyApp) SaveUser(username string) rev.Result { // Username (required) must be between 4 and 15 letters (inclusive). c.Validation.Required(username) ... 阅读全文

Go Web开发之Revel - 测试

2013-01-09 09:44 by Danny.tian, 2466 阅读, 收藏,
摘要: Revel提供了一个测试框架,这使得在应用程序中写和运行测试函数变得很容易.skeleton应用程序带有一个简单的测试来帮助我们测试.概要测试保存在tests目录corp/myapp app/ conf/ public/ tests/ <----一个简单的测试看起来像下面这样:type ApplicationTest struct { rev.TestSuite}func (t ApplicationTest) Before() { println("Set up")}func (t ApplicationTest) TestThatIndexPageWo... 阅读全文

Go Web开发之Revel - 命令行工具

2013-01-10 10:09 by Danny.tian, 2397 阅读, 收藏,
摘要: 构建和运行为了使用Revel你必须构建命令行工具.从你的GOPATH根目录开始.$ go build -o bin/revel github.com/robfig/revel/cmd现在运行:$ bin/revel~~ revel! http://robfig.github.com/revel~usage: revel command [arguments]The commands are: run run a Revel application new create a skeleton Revel application clean ... 阅读全文

Go Web开发之Revel - 日志

2013-01-09 16:17 by Danny.tian, 2262 阅读, 收藏,
摘要: Revel提供4个日志记录器TRACE - 只有debug信息.INFO - 信息报告.WARN - 一些意外的但无害的.ERROR - 错误信息,不需要看一看了.日志可以在app.conf中配置. 下面是一个例子:app.name = sampleapp[dev]log.trace.output = stdoutlog.info.output = stdoutlog.warn.output = stderrlog.error.output = stderrlog.trace.prefix = "TRACE "log.info.prefix = "INFO &qu 阅读全文

Go Web开发之Revel - 部署

2013-01-09 16:17 by Danny.tian, 2091 阅读, 收藏,
摘要: SCPRevel应用程序可以被部署到没有安装Go功能的机器上. 命令行工具提供了package命令,它可以编译和打包应用程序并附带一个运行它的脚本.一个典型的部署看起来像下面这样:# Run and test my app.$ revel run import/path/to/app.. test app ..# Package it up.$ revel package import/path/to/appYour archive is ready: app.zip# Copy to the target machine.$ scp app.zip target:/srv/# Run it 阅读全文