1. 程式人生 > 實用技巧 >golang學習筆記-go mod的使用

golang學習筆記-go mod的使用

1.go modules的基本介紹

1.1 提供的命令

在go環境的shell中執行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
命令 作用

go mod download

下載模組到本地快取,快取路徑是$GOPATH/pkg/mod/cache
go mod edit 是提供了命令版編輯go.mod的功能,例如go mod edit -fmt go.mod會格式化go.mod
go mod graph 把模組之間的依賴圖顯示出來

go mod init

初始化模組(例如把原本dep管理的依賴關係轉換過來)

go mod tidy

增加缺失的包,移除沒用的包

go mod vendor

把依賴拷貝到vendor/目錄下

go mod verify

確認依賴關係

go mod why

解釋為什麼需要包和模組