Golang框架Beego在Windows環境下小試牛刀

Beego官網
beego官網 : https://beego.me/
github : https://github.com/beegocss

Beego安裝
前提: ①Go 1.1+ 以確保全部功能的正常使用②安裝 Beego 和 Bee 的開發工具③須要設置環境變量GOPATH④這裏使用git命令下載,須要下載安裝git,並配置git環境變量git

檢查go環境變量github

C:\Users\Administrator>go env set GOARCH=amd64 set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build set GOEXE=.exe set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOOS=windows set GOPATH=D:\goproject       //這裏設置了gopath
set GORACE=
set GOROOT=D:\go set GOTMPDIR=
set GOTOOLDIR=D:\go\pkg\tool\windows_amd64 set GCCGO=gccgo set CC=gcc set CXX=g++
set CGO_ENABLED=1
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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp
\go-build126928446=/tmp/go-build -gno-record-gcc-switches

固然環境變量也能夠經過在dos窗口臨時設置,這裏不作演示web

$ go get github.com/astaxie/beego //git命令下載beego
$ go get github.com/beego/bee     //git命令下載bee工具 //beege和bee是兩個概念,beego是框架,bee是工具,是命令。

正由於須要用beego框架開發項目,因此通常的項目目錄結構爲下圖docker

若是咱們一步步建立這些目錄文件,那麼就很浪費時間了,這時候用到bee工具,一步步接着走windows

D:\>bee //執行bee命令(固然也能夠忽略上一步配置環境變量,直接進入目錄執行bee命令)
Bee is a Fast and Flexible tool for managing your Beego Web Application. USAGE bee command [arguments] AVAILABLE COMMANDS version Prints the current Bee version migrate Runs database migrations api Creates a Beego API application bale Transforms non-Go files to Go source files fix Fixes your application by making it compatible with newer versions of Beego dlv Start a debugging session using Delve dockerize Generates a Dockerfile for your Beego application generate Source code generator hprose Creates an RPC application based on Hprose and Beego frameworks new Creates a Beego application pack Compresses a Beego application into a single file rs Run customized scripts run Run the application by starting a local development server server serving static content over HTTP on port Use bee help [command] for more information about a command. ADDITIONAL HELP TOPICS Use bee help [topic] for more information about that topic.

new 命令:new命令建立一個Web項目,咱們在命令下執行bee new <項目名>就能夠建立一個新的項目。api

api命令:上面的new命令是用來建立新Web項目,不過不少用戶使用beego來開發API應用,因此api命令是用來建立API應用session

執行命令建立項目app

D:\>bee new test  //這裏由於配置了bee環境變量,能夠直接這樣new。不然須要進入GOPATH/src下執行
______ | ___ \ | |_/ / ___ ___ | ___ \ / _ \ / _ \ | |_/ /|  __/|  __/ \____/  \___| \___| v1.10.0
2018/09/17 10:25:15 WARN     ▶ 0001 You current workdir is not inside $GOPATH/src. 2018/09/17 10:25:15 INFO     ▶ 0002 Creating application... create D:\goproject\src\test\ create D:\goproject\src\test\conf\ create D:\goproject\src\test\controllers\ create D:\goproject\src\test\models\ create D:\goproject\src\test\routers\ create D:\goproject\src\test\tests\ create D:\goproject\src\test\static\ create D:\goproject\src\test\static\js\ create D:\goproject\src\test\static\css\ create D:\goproject\src\test\static\img\ create D:\goproject\src\test\views\ create D:\goproject\src\test\conf\app.conf create D:\goproject\src\test\controllers\default.go create D:\goproject\src\test\views\index.tpl create D:\goproject\src\test\routers\router.go create D:\goproject\src\test\tests\default_test.go create D:\goproject\src\test\main.go 2018/09/17 10:25:15 SUCCESS  ▶ 0003 New application successfully created!

啓動服務框架

D:\goproject\src\test>go run main.go  //啓動服務
2018/09/17 10:26:52.865 [I] [asm_amd64.s:2361]  http server Running on http://:8080 //監聽8080
[beego] 2018/09/17 - 10:27:22 |            ::1| 200 |     3.0076ms|   match| GET      /     r:/ [beego] 2018/09/17 - 10:27:22 |            ::1| 200 |     1.0022ms|   match| GET      /static/js/reload.min.js [beego] 2018/09/17 - 10:27:25 |            ::1| 200 |     6.0156ms|   match| GET      /     r:/ [beego] 2018/09/17 - 10:27:25 |            ::1| 304 |           0s|   match| GET      /static/js/reload.min.js

訪問本地web

由於默認綁定的是8080端口,因此本地訪問http://localhost:8080/

相關文章
相關標籤/搜索