Golang入門教程(三)beego 框架安裝

  beego 是一個快速開發 Go 應用的 HTTP 框架,他能夠用來快速開發 API、Web 及後端服務等各類應用,是一個 RESTful 的框架,主要設計靈感來源於 tornado、sinatra 和 flask 這三個框架,可是結合了 Go 自己的一些特性(interface、struct 嵌入等)而設計的一個框架。linux

步驟:

  1. 安裝 beego 到您的 $GOPATH 中。
  2. 在您的計算機上安裝 Bee 工具。
  3. 建立一個名爲 「hello」 的應用程序。
  4. 啓動熱編譯。

一、beego 的安裝

go get github.com/astaxie/beego

更多安裝信息:https://beego.me/docs/install/git

二、bee 工具的安裝

go get github.com/beego/bee

安裝完以後,bee 可執行文件默認存放在 $GOPATH/bin 裏面,因此您須要把 $GOPATH/bin 添加到您的環境變量中,才能夠進行下一步,以下所示:github

(1)當前環境變量(Xshell 退出從新登陸後失效golang

export PATH=$PATH:/home/www/golang/gopath/bin/linux_386

疑問:我這裏怎麼多出來一個linux_386(??) shell

(2)全局環境變量修改(Xshell 退出從新登陸後不失效flask

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 設置的區別vim

  • /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

三、建立項目

bee new hello

四、執行項目

記住:要進入剛建立的新項目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

五、打開瀏覽器看看效果

 

六、視頻教程

http://edu.51cto.com/center/course/lesson/index?id=24341ruby

 

文件目錄結構

Linux 配置環境變量

export GOPATH=/home/www/golang/gopath 
export GOROOT=/usr/local/go
export GOTOOLS=$GOROOT/pkg/tool
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Windows 配置環境變量

相關文章
相關標籤/搜索