小言_互联网的博客

GOLANG:beego搭建运行初体验(一)

239人阅读  评论(0)

文档:https://beego.me/docs/quickstart/new.md

go version:go1.16 linux/amd64

beego version: v1.12.3

docker环境搭建:

go version go1.16 linux/amd64

docker run -it -v /Users/gowork/:/go/src/ -p 8000:8080 golang:latest 

 

安装beego和bee工具

由于默认下载的为国外源,众所周知的原因,安装过程会很慢,甚至timeout,所以先修改配置

go env -w GOPROXY = https://goproxy.cn,direct

 

然后安装


  
  1. go get github.com/astaxie/beego 
  2. go get github.com/beego/bee

 

快速创建项目


  
  1. root@dd59085ad403:/go/src # bee new test
  2. 2021/02/25 02:18:14 INFO ▶ 0001 generate new project support go modules.
  3. 2021/02/25 02:18:14 INFO ▶ 0002 Creating application...
  4. create / go/src/ test/go.mod
  5. create / go/src/ test/
  6. create / go/src/ test/conf/
  7. create / go/src/ test/controllers/
  8. create / go/src/ test/models/
  9. create / go/src/ test/routers/
  10. create / go/src/ test/tests/
  11. create / go/src/ test/ static/
  12. create / go/src/ test/ static/js/
  13. create / go/src/ test/ static/css/
  14. create / go/src/ test/ static/img/
  15. create / go/src/ test/views/
  16. create / go/src/ test/conf/app.conf
  17. create / go/src/ test/controllers/default.go
  18. create / go/src/ test/views/index.tpl
  19. create / go/src/ test/routers/router.go
  20. create / go/src/ test/tests/default_test.go
  21. create / go/src/ test/main.go
  22. 2021/ 02/ 25 02: 18: 14 SUCCESS0003 New application successfully created!

 

跑bee run是出现了报错


  
  1. root@dd59085ad403 :/go/src/test # bee run
  2. _____ _
  3. | ___ \
  4. | |_/ / ___ ___
  5. | __ _ \ / _ \ / _ \
  6. | | _/ /| __/ | __/
  7. \____/ \___| \__ _ | v1.12.0
  8. 2021/02/25 02:21:14 INFO ▶ 0001 Using 'test' as 'appname'
  9. 2021/02/25 02:21:14 INFO ▶ 0002 Initializing watcher...
  10. go: github.com/astaxie/beego@v1.12.1: missing go.sum entry; to add it:
  11. go mod download github.com/astaxie/beego
  12. 2021/02/25 02:21:15 ERROR ▶ 0003 Failed to build the application: go: github.com/astaxie/beego@v1.12.1: missing go.sum entry; to add it:
  13. go mod download github.com/astaxie/beego

 

翻了下资料,缺少对应的引入文件`github.com/astaxie/beego`,重新`go get github.com/astaxie/beego`即可


  
  1. root@dd59085ad403 :/go/src/test # go get github.com/astaxie/beego
  2. go get: upgraded github.com/astaxie/beego v1. 12.1 => v1. 12.3

 

然后再次运行


  
  1. root@dd59085ad403:/go/src/test# bee run
  2. ______
  3. | ___ \
  4. | |_/ / ___ ___
  5. | ___ \ / _ \ / _ \
  6. | |_/ /| __/| __/
  7. \____/ \___| \___| v1.12.0
  8. 2021 /02/25 02 :24:50 INFO 0001 Using 'test' as 'appname'
  9. 2021 /02/25 02 :24:50 INFO 0002 Initializing watcher...
  10. test/controllers
  11. test/routers
  12. test
  13. 2021 /02/25 02 :24:53 SUCCESS 0003 Built Successfully!
  14. 2021 /02/25 02 :24:53 INFO 0004 Restarting 'test' ...
  15. 2021 /02/25 02 :24:53 SUCCESS 0005 './test' is running...
  16. 2021 /02/25 02 :24:53.182 [ I] [ asm_amd64.s:1371] http server Running on http://:8080

 

这样提示表名运行成功了。go是可以不用依赖nginx的,打开浏览器输入http://localhost:8080检查一下,有页面输出,bingo!!


转载:https://blog.csdn.net/u014043168/article/details/114065616
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场