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
demo
golang
可以看到,多生成了一個文件go.sum
ll

go.mod的內容會多了以下內容
demo
go.sum的內容
yes
end

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章