Golang入门教程(三)beego 框架安装
beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API、Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado、sinatra 和 flask 这三个框架,但是结合了 Go 本身的一些特性(interface、struct 嵌入等)而设计的一个框架。
步骤:
- 安装 beego 到您的 $GOPATH 中。
- 在您的计算机上安装 Bee 工具。
- 创建一个名为 “hello” 的应用程序。
- 启动热编译。
1、beego 的安装
go get github.com/astaxie/beego
更多安装信息:https://beego.me/docs/install/
2、bee 工具的安装
go get github.com/beego/bee
安装完之后,bee 可执行文件默认存放在 $GOPATH/bin 里面,所以您需要把 $GOPATH/bin 添加到您的环境变量中,才可以进行下一步,如下所示:
(1)当前环境变量(Xshell 退出重新登录后失效)
export PATH=$PATH:/home/www/golang/gopath/bin/linux_386
疑问:我这里怎么多出来一个linux_386(??)
(2)全局环境变量修改(Xshell 退出重新登录后不失效)
1 2 3 4 5 6 7 | sudo vim /etc/profile // 添加以下内容 export PATH=$PATH: /home/www/golang/gopath/bin/linux_386 // 编辑结束后执行 source profile 或 执行点命令 . /profile , PATH的值就会立即生效了 source /etc/profile |
(3)关于 /etc/profile 和 ./profile 设置的区别
- /etc/profile 用于整个系统所有用户
- ~/.bash_profile, ~/.profile和~/.bashrc 用于各个用户,这里的"~"符号就是各当前用户的$HOME,~/.bash_profile 和 ~/.profile 只在登陆时读取一次。
(4)环境变量没有安装成功的话会出现以下情况
bee new hello
No command 'bee' found, did you mean:
Command 'tee' from package 'coreutils' (main)
Command 'beef' from package 'beef' (universe)
Command 'ree' from package 'ree' (universe)
Command 'btee' from package 'ruby-bcat' (universe)
Command 'beer' from package 'gerstensaft' (universe)
Command 'pee' from package 'moreutils' (universe)
Command 'bbe' from package 'bbe' (universe)
Command 'be' from package 'bugs-everywhere' (universe)
Command 'beep' from package 'beep' (universe)
Command 'see' from package 'mime-support' (main)
Command 'ben' from package 'ben' (universe)
Command 'bel' from package 'belier' (universe)
Command 'beet' from package 'beets' (universe)
bee: command not found
3、创建项目
bee new hello
4、执行项目
记住:要进入刚创建的新项目hello
/home/www/golang/gopath/src/hello/
www@TinywanAliYun:~/golang/gopath/src/hello$ ls
conf controllers main.go models routers static tests views
www@TinywanAliYun:~/golang/gopath/src/hello$ bee run
5、打开浏览器看看效果
6、视频教程
http://edu.51cto.com/center/course/lesson/index?id=24341
文件目录结构
Linux 配置环境变量
1 2 3 4 | export GOPATH= /home/www/golang/gopath export GOROOT= /usr/local/go export GOTOOLS=$GOROOT /pkg/tool export PATH=$PATH:$GOROOT /bin :$GOPATH /bin |
Windows 配置环境变量
分类:
Golang/Java/Rust
标签:
Go
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构