這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
Revel架構安裝
官網:http://revel.github.io/tutorial/index.html
中文社區:http://www.gorevel.cn/
一、安裝Revel架構
下載Revel架構源碼,將其源碼放入%GOPATH%src/github.com/revel/revel目錄下,然後在%GOPATH%src目錄下進行編譯操作:
編譯:go build github.com/revel/revel
結果報錯,如下:
src\github.com\revel\revel\revel.go:17:2: cannot find package "github.com/ag
torre/gocolorize" in any of:
D:\Go\src\github.com\agtorre\gocolorize (from $GOROOT)
D:\GO_WorkSpace\src\github.com\agtorre\gocolorize (from $GOPATH)
src\github.com\revel\revel\compress.go:13:2: cannot find package "github.com
/klauspost/compress/gzip" in any of:
D:\Go\src\github.com\klauspost\compress\gzip (from $GOROOT)
D:\GO_WorkSpace\src\github.com\klauspost\compress\gzip (from $GOPATH
)
src\github.com\revel\revel\compress.go:14:2: cannot find package "github.com
/klauspost/compress/zlib" in any of:
D:\Go\src\github.com\klauspost\compress\zlib (from $GOROOT)
D:\GO_WorkSpace\src\github.com\klauspost\compress\zlib (from $GOPATH
)
src\github.com\revel\revel\i18n.go:15:2: cannot find package "github.com/rev
el/config" in any of:
D:\Go\src\github.com\revel\config (from $GOROOT)
D:\GO_WorkSpace\src\github.com\revel\config (from $GOPATH)
src\github.com\revel\revel\router.go:18:2: cannot find package "github.com/r
evel/pathtree" in any of:
D:\Go\src\github.com\revel\pathtree (from $GOROOT)
D:\GO_WorkSpace\src\github.com\revel\pathtree (from $GOPATH)
import cycle not allowed
package github.com/revel/revel
imports golang.org/x/net/websocket
imports golang.org/x/net/websocket
src\golang.org\x\net\websocket\watcher.go:13:2: cannot find package "gopkg.i
n/fsnotify.v1" in any of:
D:\Go\src\gopkg.in\fsnotify.v1 (from $GOROOT)
D:\GO_WorkSpace\src\gopkg.in\fsnotify.v1 (from $GOPATH)
根據錯誤資訊,分別下載以下包:
github.com/agtorre/gocolorize
github.com/klauspost/compress
github.com/revel/config
github.com/revel/pathtree
golang.org/x/net
gopkg.in/fsnotify.v1
將各個包的源碼放在相應的路徑下。然後再次執行:
go build github.com/revel/revel
編譯成功
二、安裝Revel命令列工具
下載Revel命令列工具源碼,將其源碼放入%GOPATH%src/github.com/revel/cmd目錄下,然後在%GOPATH%src目錄下進行編譯操作:
編譯: go build github.com/revel/cmd/revel
結果報錯,如下:
D:\GO_WorkSpace\src\github.com\revel\cmd\revel\test.go:19:2: cannot find package "github.com/revel/modules/testrunner/app/controllers" in any of:
D:\Go\src\github.com\revel\modules\testrunner\app\controllers (from $GOROOT)
D:\GO_WorkSpace\src\github.com\revel\modules\testrunner\app\controllers (from $GOPATH)
根據錯誤資訊,下載以下包:
github.com/revel/modules
將其源碼放在相應的路徑下。然後再次執行:
go build github.com/revel/cmd/revel
編譯成功
三、建立 Revel 應用
重啟命令列工具,然後在%GOPATH%src目錄下建立 Revel 應用。
命令:
revel new MyRevelApp
revel run MyRevelApp
四、開啟瀏覽器訪問 http://localhost:9000
預設監聽9000連接埠。
五、Revel指令
1、revel
在命令列輸入`revel`,得到所有revel指令的說明:
usage: revel command [arguments]
The commands are:
new create a skeleton Revel application
run run a Revel application
build build a Revel application (e.g. for deployment)
package package a Revel application (e.g. for deployment)
clean clean a Revel application's temp files
test run all tests from the command-line
version displays the Revel Framework and Go version
Use "revel help [command]" for more information.
2、revel help [command]
revel help [command]用於擷取相關指令的協助說明。例:
在命令列輸入`revel help new`,得到所有關於new指令的說明:
usage: revel new [path] [skeleton]
New creates a few files to get a new Revel application running quickly.
It puts all of the files in the given import path, taking the final element in
the path to be the app name.
Skeleton is an optional argument, provided as an import path
For example:
revel new import/path/helloworld
revel new import/path/helloworld import/path/skeleton
六、Revel架構的MVC模式概念
MVC(模型-視圖-控制器):
模型:描述基本的資料對象,特定的查詢和更新邏輯。
視圖:一些模板,用於將資料呈現給使用者。
控制器:執行使用者的請求,準備使用者所需的資料,並指定模板進行渲染。
具體參考:
http://www.gorevel.cn/docs/manual/concepts.html
七、Revel路由配置
在Conf目錄下的routes檔案進行配置
具體參考:
http://www.gorevel.cn/docs/manual/routing.html
391 次點擊