Go的安裝
首先需要在官網Golang.google.cn下載.msi 后綴(在下載串列中可以找到該檔案,如go1.4.2.windows-amd64.msi)的安裝包來安裝,
默認情況下 .msi 檔案會安裝在 c:\Go 目錄下,你可以將 c:\Go\bin 目錄添加到 Path 環境變數中,添加后你需要重啟命令視窗才能生效,
安裝成功后在命令列視窗執行命令
go
將會出現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.
環境變數GO111MODULE的修改
在安裝第三方包的時候,由于網路問題golang.org在國內無法正常使用,導致我們無法使用第三方包管理工具,因此可以通過修改系統環境變數將golang.org切換至國內CDN,
windows下,執行如下命令
$env:GO111MODULE="on"
go.mod是一個go專案的依賴管理檔案,關于go.mod的問題此處不再拓展,這里面GO111MODULE的引數是這是專案與go.mod的關系,可選 auto on 和 off,auto 根據是否在 src 下自動判定, on 只用 go.mod , off只用 src,此處引數on可以設定為on或者auto,
國內CDN的切換
可以通過設定GOPROXY環境變數來實作國內CDN的切換,可以通過執行下面任一命令切換至七牛云,阿里云或是官方
$env:GOPROXY="https://goproxy.cn,direct" #七牛云
$env:GOPROXY="https://mirrors.aliyun.com/goproxy/,direct" #阿里云
$env:GOPROXY="https://goproxy.io,direct" #官方
Gin的安裝
執行命令來完成Gin的安裝
go get -u -v github.com/gin-gonic/gin
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/135178.html
標籤:其他
