第1章 课程介绍
1-1 Google资深工程师深度讲解go语言
1-2 安装与环境
1-3 国内镜像配置
1-4 IntelliJ Idea的安装和配置
1-5 vscode的安装和配置
1-1 Google资深工程师深度讲解go语言
1-2 安装与环境
go安装包下载的国内网址:
https://studygolang.com/dl
选择版本大于1.13及以上,因为从1.13版本之后,增加了镜像功能。下载成功后(我自己下载的是for Mac OS 版本),直接点击安装即可。
1-3 国内镜像配置
1、安装完成后,首先可以进行验证,即直接在命令行窗口执行go:
xls@xls-2:~$ go Go is a tool for managing Go source code. Usage: go <command> [arguments] The commands are: bug start a bug report build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go files by processing source get add dependencies to current module and install them install compile and install packages and dependencies list list packages or modules mod module maintenance run compile and run Go program test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help <command>" for more information about a command. Additional help topics: buildmode build modes c calling between Go and C cache build and test caching environment environment variables filetype file types go.mod the go.mod file gopath GOPATH environment variable gopath-get legacy GOPATH go get goproxy module proxy protocol importpath import path syntax modules modules, module versions, and more module-get module-aware go get module-auth module authentication using go.sum module-private module configuration for non-public modules packages package lists and patterns testflag testing flags testfunc testing functions Use "go help <topic>" for more information about that topic.
2、还可以查看目前安装的版本:
xls@xls-2:~$ go version go version go1.14.2 darwin/amd64
3、列出当前编译器生效的配置:
xls@xls-2:~$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/xls/Library/Caches/go-build" GOENV="/Users/xls/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/xls/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GCCGO="gccgo" AR="ar" 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/nq/5hf1n2jx56g3fyyhhd_118sc0000gn/T/go-build128111798=/tmp/go-build -gno-record-gcc-switches -fno-common"
4、其中的GOPROXY就是go的代理或者说是镜像,一般用于我们去下载一些包或者拉取一些依赖等,目前我们还没修改前,镜像指向的是 proxy.golang.org,即默认值。接下来我们可以配置新的镜像,打开网站:
https://github.com/goproxy/goproxy.cn
在命令行下执行:
export GOPROXY=https://goproxy.cn
除此之外,还有一个环境需要进行配置:
GO111MODULE=""
需要将其改为 on,即在命令行下执行:
export GO111MODULE=on
github的参考:
5、关于go module以及GOPATH在后序的课程中会进行讲解。
6、安装goimports工具:
命令行下直接进行安装:
go get -v -u golang.org/x/tools/cmd/goimports
1-4 IntelliJ Idea的安装和配置
1、在Idea中安装两个插件分别是go以及file watchers(格式化代码):
2、接下来就可以创建工程了
创建go文件:
3、通过file watchers添加一个goimports
配置完之后可以进行格式化、代码补全等功能。
4、模块文件
1-5 vscode的安装和配置