官網安裝
安裝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()
}