创建Revel项目
-
输入GOPATH的路径(因操作系统而异):
#Linux #cd $GOPATH cd %GOPATH%
-
安装Revel
go get -u github.com/revel/cmd/revel
-
创建项目
revel new -a duneng -r
-
测试 创建项目完成后,即可通过http://localhost:9000访问
-
运行项目
revel run duneng
-
编译项目
#编译项目,并输出到release目录 revel build duneng release #运行项目 duneng.exe --importPath duneng -srcPath src -runMode dev #或 duneng.exe --importPath duneng
编译后也可以直接执行输出目录的run.bat,但是需要修改一下错误,如下:
@echo off # duneng.exe -importPath duneng -srcPath "%CD%\src" -runMode dev # 去掉%CD%,此命令不适用于我的“Windows 10” duneng.exe -importPath duneng -srcPath "src" -runMode dev
问题解决
-
解决依赖包不能下载问题,如下:
Error stack [utils.go:109 command_config.go:232 new.go:187 new.go:126 revel.go:109 proc.go:200 asm_amd64.s:1337] ERROR 09:31:07 new.go:187: Failed to import package error="exit status 1" gopath=C:\\Users\\litian020\\go GO-ROOT=C:\\Go\\ output="package golang.org/x/net/websocket: unrecognized import path \"golang.org/x/net/websocket\" (https fetch: Get https://golang.org/x/net/websocket?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)\n" ERROR 09:31:07 proc.go:200: Unable to execute error="Failed to fetch revel github.com/revel/revel[error exit status 1]"
#进入src目录 cd %GOPATH%\src #pull包到本地 git clone --depth 1 https://github.com/golang/net.git golang.org/x/net git clone --depth 1 https://github.com/fsnotify/fsnotify.git gopkg.in/fsnotify/fsnotify.v1 git clone --depth 1 https://github.com/natefinch/lumberjack.git gopkg.in/natefinch/lumberjack.v2 git clone --depth 1 -b v0 https://github.com/go-stack/stack.git gopkg.in/stack.v0 #重新创建项目即可 revel new -a duneng -r