Windows安裝beego框架環境
1、到官網下載安裝包,地址是:https://golang.org/dl/ ,自選對應環境;
2、在任意目錄,新建資料夾E:\work\code\go,cmd進入該目錄,執行 go env 檢視環境配置;
3、設定golang的GOPATH環境
set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\Administrator\AppData\Local\go-build set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=C:\Users\Administrator\go set GOPROXY= set GORACE= set GOROOT=C:\Go set GOTMPDIR= set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD= set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessag e-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build05377 4846=/tmp/go-build -gno-record-gcc-switches
單次配置:執行 set GOATH=E:\work\code\go
永久配置GOPATH,需要在系統環境變數中新增一個GOPATH的配置項,由此可以通過go將beego與bee的包下到該GOPATH目錄中的src目錄中來
4、在E:\work\code\go下執行
go get github.com/beego/bee
go get github.com/astaxie/beego
下載bee,下載beego
5、配置bee環境變數,將E:\work\code\go\bin配置到系統path環境變數中,用於全域性使用bee
6、使用bee建立一個新專案
bee new webApp
此時,會發現在E:\work\code\go\src目錄下會多出一個webApp的Go專案
7、bee run webApp
如果報如下錯誤,別慌
2018/12/26 11:18:03 WARN ▶ 0001 Running application outside of GOPATH
2018/12/26 11:18:03 INFO ▶ 0002 Using 'webApp' as 'appname'
2018/12/26 11:18:03 INFO ▶ 0003 Initializing watcher...
can't load package: package .: no Go files in E:\work\code\go\src
2018/12/26 11:18:03 ERROR ▶ 0004 Failed to build the application: can't load
package: package .: no Go files in E:\work\code\go\src
直接到webApp目錄底下,執行go run main.go
開啟瀏覽器輸入 http://localhost:8080/ 可以看到歡迎頁面