1、在使用bee new 创建一个beego项目后,进入项目目录 执行 bee run 启动失败,下面大概记录一下解决方法。
bee new 新建项目成功;
进入到项目中,执行bee run 失败
报错内容如下:
G:\GoWorkspace\src\mybeego>bee run
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.11.0
2020/07/19 22:47:01 INFO ▶ 0001 Using 'mybeego' as 'appname'
2020/07/19 22:47:01 INFO ▶ 0002 Initializing watcher...
..\github.com\astaxie\beego\app.go:33:2: cannot find package "golang.org/x/crypto/acme/autocert" in any of:
G:\Go\src\golang.org\x\crypto\acme\autocert (from $GOROOT)
G:\GoWorkspace\src\golang.org\x\crypto\acme\autocert (from $GOPATH)
G:\GoWorkspace\bin\src\golang.org\x\crypto\acme\autocert
..\github.com\prometheus\client_golang\prometheus\process_collector_windows.go:20:2: cannot find package "golang.org/x/sys/windows
" in any of:
G:\Go\src\golang.org\x\sys\windows (from $GOROOT)
G:\GoWorkspace\src\golang.org\x\sys\windows (from $GOPATH)
G:\GoWorkspace\bin\src\golang.org\x\sys\windows
2020/07/19 22:47:01 ERROR ▶ 0003 Failed to build the application: ..\github.com\astaxie\beego\app.go:33:2: cannot find package
"golang.org/x/crypto/acme/autocert" in any of:
G:\Go\src\golang.org\x\crypto\acme\autocert (from $GOROOT)
G:\GoWorkspace\src\golang.org\x\crypto\acme\autocert (from $GOPATH)
G:\GoWorkspace\bin\src\golang.org\x\crypto\acme\autocert
..\github.com\prometheus\client_golang\prometheus\process_collector_windows.go:20:2: cannot find package "golang.org/x/sys/windows
" in any of:
解决方法:
对比了一下成功运行的beego项目,发现新建的项目缺少go.mod文件,.刚刚生成的beego项目没有依赖管理包的文件,所有需要生成一个。
于是使用 go mod init 命令初始化一个go.mod文件到当前目录。
在新建项目下执行: go mod init
G:\GoWorkspace\src\mybeego>go mod init
go: creating new go.mod: module mybeego
G:\GoWorkspace\src\mybeego>
再次运行 bee run:
G:\GoWorkspace\src\mybeego>bee run
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.11.0
2020/07/19 22:55:48 INFO ▶ 0001 Using 'mybeego' as 'appname'
2020/07/19 22:55:48 INFO ▶ 0002 Initializing watcher...
mybeego/controllers
mybeego/routers
mybeego
2020/07/19 22:56:08 SUCCESS ▶ 0003 Built Successfully!
2020/07/19 22:56:08 INFO ▶ 0004 Restarting 'mybeego.exe'...
2020/07/19 22:56:08 SUCCESS ▶ 0005 './mybeego.exe' is running...
2020/07/19 22:56:08.646 [I] [asm_amd64.s:1357] http server Running on http://:8080
哈,beego项目成功跑起来了!
浏览器访问:http://localhost:8080/
搞定。。。