golang 1.12包管理探究

1.安装golang
下载对应系统的Go安装包
https://studygolang.com/dl

2.安装完之后验证

➜   go version
go version go1.12.2 darwin/amd64

3.设置GO111MODULE环境变量

 export GO111MODULE=auto 
➜   echo $GO111MODULE
auto
go env
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/Users/xinzhiyun/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xinzhiyun/112-k8s"
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="/Users/xinzhiyun/golang122/go.mod"
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/71/rt2h8r3n7_72_hzqbln63df40000gn/T/go-build382191781=/tmp/go-build -gno-record-gcc-switches -fno-common"

4.在你喜欢的目录创建测试项目

➜  cat demo.go 
package main

import "github.com/astaxie/beego"

func main() {
    beego.Run()
}

在项目目录下执行

go mod init hello

会生成一下文件go.mod

➜   cat go.mod 
module hello

go 1.12

运行demo.go



go run demo.go
  golang122 go run demo.go 
go: finding github.com/astaxie/beego v1.11.1
go: downloading github.com/astaxie/beego v1.11.1
go: extracting github.com/astaxie/beego v1.11.1
go: finding github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd
go: finding github.com/mattn/go-sqlite3 v1.10.0
go: finding github.com/elazarl/go-bindata-assetfs v1.0.0
go: finding github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712
go: finding github.com/pelletier/go-toml v1.2.0
go: finding github.com/go-redis/redis v6.14.2+incompatible
go: finding github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb
go: finding github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58
go: finding github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542
go: finding github.com/go-sql-driver/mysql v1.4.1
go: finding github.com/gogo/protobuf v1.1.1
go: finding github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec
go: finding github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
go: finding github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c
go: finding github.com/casbin/casbin v1.7.0
go: finding github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db
go: finding github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d
go: finding github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76
go: finding gopkg.in/yaml.v2 v2.2.1
go: finding github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a
go: finding github.com/lib/pq v1.0.0
go: finding github.com/pkg/errors v0.8.0
go: finding github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373
go: finding github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b
go: finding github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c
go: finding github.com/belogik/goes v0.0.0-20151229125003-e54d722c3aff
go: finding github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737

该过程自动把依赖下载到$GOPATH/pkg/mod

golang 1.12包管理探究_第1张图片
可以看到,多生成了一个文件go.sum
golang 1.12包管理探究_第2张图片

go.mod的内容会多了以下内容
golang 1.12包管理探究_第3张图片
go.sum的内容

end

参考:
拜拜了,GOPATH君!新版本Golang的包管理入门教程

你可能感兴趣的:(golang)