Beego安裝與環境配置

官網安裝

https://beego.me/quickstart

安裝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()
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章