1. 程式人生 > >linux下安裝beego(linux(centos/ubuntu) install beego)

linux下安裝beego(linux(centos/ubuntu) install beego)


1、下載安裝:

$ go get github.com/astaxie/beego

$ go get github.com/beego/bee


2、將 $GOPATH/bin 加入到你的 $PATH 變數中。


3、檢測安裝:

$ cd $GOPATH/src
$ bee new hello
$ cd hello
$ bee run hello


一旦程式開始執行,您就可以在瀏覽器中開啟 http://localhost:8080/ 進行訪問。


4、簡單示例:
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()}


把上面的程式碼儲存為 hello.go,然後通過命令列進行編譯並執行:
$ go build -o hello hello.go

$ ./hello


瀏覽器輸入: http://127.0.0.1:8080

顯示: “hello world”。