):来读一下Revel的网页试试看
我想阅读一下Golang的Web框架Revel的官方网页。
听说它是基于Go语言的高生产力Web框架。
目前最新的发布版本是2015/3/25的0.12.0版本。
特色
热代码重载
Revel会自动编译编辑过的代码模板。即使编译失败,也会展示清晰的解释。同样适用于运行时错误。
综合的 de)
Revel提供了以下功能。
-
- routing
-
- parameter parsing
-
- validation
-
- session/flash
-
- templating
-
- caching
-
- job running
-
- a testing framework
- internationalization
高性能
Revel是基于Go Http服务器构建的,并在多种负载情况下,与Rails等相比表现出3到10倍的速度。
框架设计
同步的
Go Http 服务器使用 Go 协程来处理每个请求,可以轻松编写从回调中解放出来的代码。
无国籍
为了满足可能发生的伸缩需求,Revel不保持状态。例如,会话通过用户的Cookie提供,缓存则存储在Redis或内存中。
模块化
Revel以可组合的中间件模块——过滤器为核心进行构建。这些过滤器被实现为处理请求的函数。开发者可以自由替换过滤器。
快速开始
Revel在提供示範應用程序以演示基本使用方法。
使用方法:
1. 安裝Revel
go get github.com/revel/revel
2. 安裝Revel命令行工具
go get github.com/revel/cmd/revel
3. 安裝示範應用程式
go get github.com/revel/samples
4. 啟動Chat示範
revel run github.com/revel/samples/chat
5. 開啟 http://localhost:9000/
因为我正在Cloud9上进行测试,所以我对src/revel/samples/chat/conf/app.conf进行了以下编辑。
http.addr=0.0.0.0
http.port=8080
我会在下方附上那次执行的结果。
~/workspace (master) $ export GOPATH=~/workspace/golang/
~/workspace (master) $ cd golang/
~/workspace/golang (master) $ go get github.com/revel/revel
~/workspace/golang (master) $ go get github.com/revel/cmd/revel
qooq@demo-project:~/workspace/golang (master) $ export PATH=$PATH:~/workspace/golang/bin
~/workspace/golang (master) $ go get github.com/revel/samples
package github.com/revel/samples
imports github.com/revel/samples
imports github.com/revel/samples: no buildable Go source files in /home/ubuntu/workspace/golang/src/github.com/revel/samples
~/workspace/golang (master) $ revel run github.com/revel/samples/chat
~
~ revel! http://revel.github.io
~
2015/04/21 01:12:57 revel.go:329: Loaded module static
2015/04/21 01:12:57 revel.go:329: Loaded module testrunner
2015/04/21 01:12:57 revel.go:206: Initialized Revel v0.12.0 (2015-03-25) for >= go1.3
2015/04/21 01:12:57 run.go:57: Running chat (github.com/revel/samples/chat) in dev mode
2015/04/21 01:12:57 harness.go:165: Listening on 0.0.0.0:8080
新建和执行新应用程序
1. 创建应用程序使用 revel new github.com/my-account/my-app
2. 如果使用 Cloud9,请编辑 app.conf 文件
3. 运行应用程序使用 revel run github.com/my-account/my-app
# The IP address on which to listen.
http.addr = 0.0.0.0
# The port on which to listen.
http.port = 8080
$ revel new github.com/kazusa-qooq/my-app
~
~ revel! http://revel.github.io
~
Your application is ready:
/home/ubuntu/workspace/golang/src/github.com/kazusa-qooq/my-app
You can run it with:
revel run github.com/kazusa-qooq/my-app
$ revel run github.com/kazusa-qooq/my-app
~
~ revel! http://revel.github.io
~
INFO 2015/04/21 01:32:58 revel.go:329: Loaded module testrunner
INFO 2015/04/21 01:32:58 revel.go:329: Loaded module static
INFO 2015/04/21 01:32:58 revel.go:206: Initialized Revel v0.12.0 (2015-03-25) for >= go1.3
INFO 2015/04/21 01:32:58 run.go:57: Running my-app (github.com/kazusa-qooq/my-app) in dev mode
INFO 2015/04/21 01:32:58 harness.go:165: Listening on 0.0.0.0:8080
INFO 2015/04/21 01:32:58 build.go:172: Cleaning dir tmp
ERROR 2015/04/21 01:32:58 build.go:176: Failed to clean dir: open /home/ubuntu/workspace/golang/src/github.com/kazusa-qooq/my-app/app/tmp: no such file or directory
INFO 2015/04/21 01:32:58 build.go:172: Cleaning dir routes
ERROR 2015/04/21 01:32:58 build.go:176: Failed to clean dir: open /home/ubuntu/workspace/golang/src/github.com/kazusa-qooq/my-app/app/routes: no such file or directory
INFO 2015/04/21 01:32:58 build.go:172: Cleaning dir tmp
ERROR 2015/04/21 01:32:58 build.go:176: Failed to clean dir: open /home/ubuntu/workspace/golang/src/github.com/kazusa-qooq/my-app/app/tmp: no such file or directory
INFO 2015/04/21 01:32:58 build.go:172: Cleaning dir routes
ERROR 2015/04/21 01:32:58 build.go:176: Failed to clean dir: open /home/ubuntu/workspace/golang/src/github.com/kazusa-qooq/my-app/app/routes: no such file or directory
INFO 2015/04/21 01:33:01 revel.go:329: Loaded module testrunner
INFO 2015/04/21 01:33:01 revel.go:329: Loaded module static
INFO 2015/04/21 01:33:01 revel.go:206: Initialized Revel v0.12.0 (2015-03-25) for >= go1.3
INFO 2015/04/21 01:33:01 main.go:30: Running revel server
Go to /@tests to run the tests.
Listening on 0.0.0.0:49616...
有点像错误的问题出现了,但是服务器启动成功了,我先关闭一下。
下次我们会读一下Revel的概览。