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


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

步驟:

  1. 安裝 beego 到您的 $GOPATH 中。
  2. 在您的計算機上安裝 Bee 工具。
  3. 創建一個名為 “hello” 的應用程序。
  4. 啟動熱編譯。

1、beego 的安裝

go get github.com/astaxie/beego

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

2、bee 工具的安裝

go get github.com/beego/bee

安裝完之后,bee 可執行文件默認存放在 $GOPATH/bin 里面,所以您需要把 $GOPATH/bin 添加到您的環境變量中,才可以進行下一步,如下所示:

(1)當前環境變量(Xshell 退出重新登錄后失效

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

疑問:我這里怎么多出來一個linux_386(??) 

(2)全局環境變量修改(Xshell 退出重新登錄后不失效

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

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

3、創建項目

bee new hello

4、執行項目

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

5、打開瀏覽器看看效果

 

6、視頻教程

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

 

文件目錄結構

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 配置環境變量

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM