以呼叫client go為例子
1,編輯/etc/profile
export GOPATH=/data1/go-workspace/
export PATH=$PATH:/usr/local/go/bin
export GOPROXY=https://goproxy.cn //修改代理
export GO111MODULE=on 啟動go mod
export GOROOT=/usr/local/go
2, go get k8s.io/client-go
拿到版本號
root@honglei-virtual-machine:/data1/go-workspace/src/k8s.io# go get k8s.io/client-go@master
go: downloading k8s.io/client-go v0.0.0-20201101202356-852de461ed6c
go: k8s.io/client-go master => v0.0.0-20201101202356-852de461ed6c
3,在自己的專案里 go mod init 生成go.mod檔案
在go.mod檔案中加入
require (
k8s.io/client-go v0.0.0-20201101202356-852de461ed6c
)
4,執行 go mod download
此時會生成go.sum
5,此時可編譯自己的檔案了
go build main.go //此時會根據需要自動下載需要的包
6,替換掉不能直接下載的包
go mod edit -replace=golang.org/x/[email protected]=github.com/golang/[email protected]
7, 如果已經有vendor目錄
可以使用 go mod vendor 從本地vendor復制
遇到無法get的庫,手動下載放到vendor中,使用go mod vendor重新重繪
8,go mod help
Usage:
go mod <command> [arguments]
The commands are:
download download modules to local cache
edit edit go.mod from tools or scripts
graph print module requirement graph
init initialize new module in current directory
tidy add missing and remove unused modules
vendor make vendored copy of dependencies
verify verify dependencies have expected content
why explain why packages or modules are needed
Use "go help mod
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/207979.html
標籤:其他
上一篇:彩虹排序 | 荷蘭旗問題
下一篇:手寫數字圖片識別-卷積神經網路
