1.beego框架简介 - Go语言中文社区

1.beego框架简介


beego 简介

beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API、Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado、sinatra 和 flask 这三个框架,但是结合了 Go 本身的一些特性(interface、struct 嵌入等)而设计的一个框架。

beego 的架构

image.png

beego 的执行逻辑

image.png

beego 项目结构

image.png

beego 安装

go get github.com/astaxie/beego

bee工具

go get github.com/beego/bee

1.new 命令(PC)

new 命令是新建一个 Web 项目,我们在命令行下执行 bee new <项目名> 就可以创建一个新的项目。但是注意该命令必须在 $GOPATH/src 下执行

2.api 命令(App)

上面的 new 命令是用来新建 Web 项目,不过很多用户使用 beego 来开发 API 应用。所以这个 api 命令就是用来创建 API 应用的

3.run 命令

我们在开发 Go 项目的时候最大的问题是经常需要自己手动去编译再运行,bee run 命令是监控 beego 的项目,通过 fsnotify监控文件系统。但是注意该命令必须在$GOPATH/src/appname下执行。

Last login: Sun Apr 28 18:24:56 on ttys000
majianghaideMacBook-Pro:~ majianghai$ bee new webBeeProject
______
| ___ 
| |_/ /  ___   ___
| ___  / _  / _ 
| |_/ /|  __/|  __/
____/  ___| ___| v1.10.0
2019/04/28 18:37:34 WARN     ▶ 0001 You current workdir is not inside $GOPATH/src.
2019/04/28 18:37:34 INFO     ▶ 0002 Creating application...
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/conf/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/controllers/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/models/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/routers/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/tests/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/static/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/static/js/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/static/css/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/static/img/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/views/
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/conf/app.conf
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/controllers/default.go
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/views/index.tpl
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/routers/router.go
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/tests/default_test.go
    create   /Users/majianghai/Applications/GOPATH/src/webBeeProject/main.go
2019/04/28 18:37:34 SUCCESS  ▶ 0003 New application successfully created!
majianghaideMacBook-Pro:~ majianghai$ bee api appBeeProject
______
| ___ 
| |_/ /  ___   ___
| ___  / _  / _ 
| |_/ /|  __/|  __/
____/  ___| ___| v1.10.0
2019/04/28 18:38:06 WARN     ▶ 0001 You current workdir is not inside $GOPATH/src.
2019/04/28 18:38:06 INFO     ▶ 0002 Creating API...
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/conf
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/controllers
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/tests
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/conf/app.conf
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/models
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/routers/
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/controllers/object.go
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/controllers/user.go
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/tests/default_test.go
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/routers/router.go
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/models/object.go
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/models/user.go
    create   /Users/majianghai/Applications/GOPATH/src/appBeeProject/main.go
2019/04/28 18:38:06 SUCCESS  ▶ 0003 New API successfully created!
majianghaideMacBook-Pro:~ majianghai$ cd /Users/majianghai/Applications/GOPATH/src/webBeeProject 
majianghaideMacBook-Pro:webBeeProject majianghai$ bee run
______
| ___ 
| |_/ /  ___   ___
| ___  / _  / _ 
| |_/ /|  __/|  __/
____/  ___| ___| v1.10.0
2019/04/28 18:38:32 INFO     ▶ 0001 Using 'webBeeProject' as 'appname'
2019/04/28 18:38:32 INFO     ▶ 0002 Initializing watcher...
webBeeProject/controllers
webBeeProject/routers
webBeeProject
2019/04/28 18:38:35 SUCCESS  ▶ 0003 Built Successfully!
2019/04/28 18:38:35 INFO     ▶ 0004 Restarting 'webBeeProject'...
2019/04/28 18:38:35 SUCCESS  ▶ 0005 './webBeeProject' is running...
2019/04/28 18:38:35.366 [I] [asm_amd64.s:1337]  http server Running on http://:8080
2019/04/28 18:38:45.154 [D] [server.go:2774]  |      127.0.0.1| 200 |   3.110237ms|   match| GET      /     r:/
2019/04/28 18:38:45.269 [D] [server.go:2774]  |      127.0.0.1| 200 |   2.313721ms|   match| GET      /static/js/reload.min.js
2019/04/28 18:41:15.093 [D] [server.go:2774]  |      127.0.0.1| 200 |  10.711678ms|   match| GET      /     r:/
2019/04/28 18:41:15.107 [D] [server.go:2774]  |      127.0.0.1| 304 |     69.038µs|   match| GET      /static/js/reload.min.js
2019/04/28 18:41:22.175 [D] [server.go:2774]  |      127.0.0.1| 200 |   2.563264ms|   match| GET      /     r:/
2019/04/28 18:41:25.664 [D] [server.go:2774]  |      127.0.0.1| 200 |   4.400769ms|   match| GET      /     r:/

版权声明:本文来源简书,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://www.jianshu.com/p/3bc18f26783a
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-01-12 11:55:50
  • 阅读 ( 1278 )
  • 分类:Go

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢