beego安装及使用

  • Post author:
  • Post category:其他


首先安装bee工具 在通过bee安装运行beego

#安装bee 要加版本号,比如链接后面加上@latest
go install https://github.com/beego/bee/v2@latest
#GOPATH的bin目录查看是否有bee
#bin目录加入环境变量中的path
#测试
bee version
#创建web项目
bee new myproject
#创建api项目
bee api apiproject
#运行
bee run
#打包 打成tar.gz包 放到服务器 解压即可部署
bee pack
#生成代码
bee generate controller hello

常见问题:

1.启动报错

2022/09/26 11:45:57 ERROR    ▶ 0004 Failed to build the application: controllers\default.go:4:2: missing go.sum entry for module providing package github.com/astaxie/beego (imported by beego); to add:
        go get beego

输入go mod tidy 在运行即可

2.bee pack 在linux下打包 解包后执行报错

panic: err: chdir /home/goapp/beego/bin/controllers: no such file or directory:                   stderr:

goroutine 1 [running]:
github.com/beego/beego/v2/server/web.initBeforeHTTPRun.func1()
        /home/go/pkg/mod/github.com/beego/beego/v2@v2.0.1/server/web/beego.go:83                   +0x19e
sync.(*Once).doSlow(0x4470d1?, 0xfc9940?)
        /usr/local/go/src/sync/once.go:68 +0xc2
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:59
github.com/beego/beego/v2/server/web.initBeforeHTTPRun()
        /home/go/pkg/mod/github.com/beego/beego/v2@v2.0.1/server/web/beego.go:69                   +0x31
github.com/beego/beego/v2/server/web.(*HttpServer).Run(0xc00000f3c8, {0x0, 0x0},                   {0x0, 0x0, 0x405491?})
        /home/go/pkg/mod/github.com/beego/beego/v2@v2.0.1/server/web/server.go:8                  5 +0x53
github.com/beego/beego/v2/server/web.Run({0x0?, 0xa3a3c0?, 0xc0000021a0?})
        /home/go/pkg/mod/github.com/beego/beego/v2@v2.0.1/server/web/beego.go:57                   +0x55
main.main()
        /home/goapp/beego/main.go:9 +0x25

解决办法 把dev环境改成prod

vim ./conf/app.conf
#改值
runmode = prod



版权声明:本文为ltgsoldier1原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。