開始使用Go Modules
命令
go modules直接作為子命令整合在go中:
go mod Go mod provides access to operations on modules. Note that support for modules is built into all the go commands, not just 'go mod'. For example, day-to-day adding, removing, upgrading, and downgrading of dependencies should be done using 'go get'. See 'go help modules' for an overview of module functionality. Usage: go mod <command> [arguments] The commands are: downloaddownload modules to local cache editedit go.mod from tools or scripts graphprint module requirement graph initinitialize new module in current directory tidyadd missing and remove unused modules vendormake vendored copy of dependencies verifyverify dependencies have expected content whyexplain why packages or modules are needed Use "go help mod <command>" for more information about a command.
理解
一個專案中由多個go package組成,這個專案被儲存在一個程式碼庫中(如git)。 也就是說這個程式碼庫中有多個go的package,如https://github.com/grpc/grpc-go這個專案。 Go Modules將這些packages稱作module,每個Go專案中會有一個go.mod檔案描述module的元資料資訊。