1.安装 go
方式1 - brew 安装
brew install go
方式2 - 安装包下载安装
https://studygolang.com/dl/golang/go1.12.5.darwin-amd64.pkg
Go环境配置
1.安装完毕后 执行 go env 查看默认配置信息
jason@local ~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jason/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jason/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ln/hbt1_qj17yxdqylb8lkdcrhc0000gn/T/go-build175946943=/tmp/go-build -gno-record-gcc-switches -fno-common"
2.配置信息说明与修改
说明:
GOROOT:就是go的安装环境
GOPATH:作为编译后二进制的存放目的地和import包时的搜索路径。其实就是go项目工作目录, GOPATH包含三个目录
- src目录下主要存放go的源文件
- pkg目录存放编译好的库文件,主要是*.a文件;
- bin目录主要存放可执行文件
修改 ~/.bash_profile,添加以下配置
export GOPATH=/Users/jason/workespace/go
export PATH=$PATH:/$GOPATH/bin
source ~/.bash_profile
2.安装Beego
go get github.com/astaxie/beego
go get github.com/beego/bee
执行 bee version,显示以下内容,说明安装成功
jason@local ~$ bee version
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
├── Beego : 1.11.2
├── GoVersion : go1.12.6
├── GOOS : darwin
├── GOARCH : amd64
├── NumCPU : 8
├── GOPATH : /Users/jason/workespace/go
├── GOROOT : /usr/local/go
├── Compiler : gc
└── Date : Wednesday, 26 Jun 2019
3.创建项目
jason@local ~$ bee new Test
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2019/06/26 20:42:02 WARN ▶ 0001 You current workdir is not inside $GOPATH/src.
2019/06/26 20:42:02 INFO ▶ 0002 Creating application...
create /Users/jason/workespace/go/src/Test/
create /Users/jason/workespace/go/src/Test/conf/
create /Users/jason/workespace/go/src/Test/controllers/
create /Users/jason/workespace/go/src/Test/models/
create /Users/jason/workespace/go/src/Test/routers/
create /Users/jason/workespace/go/src/Test/tests/
create /Users/jason/workespace/go/src/Test/static/
create /Users/jason/workespace/go/src/Test/static/js/
create /Users/jason/workespace/go/src/Test/static/css/
create /Users/jason/workespace/go/src/Test/static/img/
create /Users/jason/workespace/go/src/Test/views/
create /Users/jason/workespace/go/src/Test/conf/app.conf
create /Users/jason/workespace/go/src/Test/controllers/default.go
create /Users/jason/workespace/go/src/Test/views/index.tpl
create /Users/jason/workespace/go/src/Test/routers/router.go
create /Users/jason/workespace/go/src/Test/tests/default_test.go
create /Users/jason/workespace/go/src/Test/main.go
2019/06/26 20:42:02 SUCCESS ▶ 0003 New application successfully created!
4.运行项目
cd /Users/jason/workespace/go/src/Test/
bee run
访问 http://localhost:8080/,即可看到下图页面
![预览(https://upload-images.jianshu.io/upload_images/8579438-228347883e203858.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/840)
有疑问加站长微信联系(非本文作者)