当前位置: 首页 > 工具软件 > Revel > 使用案例 >

php revel,Revel框架安装

许天逸
2023-12-01

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

有疑问加站长微信联系(非本文作者)

 类似资料: