官网安装
安装Go环境
此处可查看之前Golang安装与环境配置一文,故省略。
安装Beego和Bee
$ go get -u github.com/astaxie/beego
$ go get -u github.com/beego/bee
配置环境变量
$ open ~/.bash_profile
在打开的文件内输入以下环境变量进行配置
export GOPATH=${HOME}/go
export PATH=${PATH}:${GOPATH}/bin
source ~/.bash_profile
查看bee
$ bee
测试bee 项目
$ cd $GOPATH/src
$ bee new helloWord
$ cd helloWord
新建main.go 将下面的代码粘贴
$ bee run
这个时候你可以打开你的浏览器,通过这个地址浏览 http://127.0.0.1:8080 返回 “hello world”。
package main
import (
"github.com/astaxie/beego"
)
type MainController struct {
beego.Controller
}
func (this *MainController) Get() {
this.Ctx.WriteString("hello world")
}
func main() {
beego.Router("/", &MainController{})
beego.Run()
}