开始使用Go Modules

2019-03-12 阅读: Go

命令

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:

        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 <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的元数据信息。

参考

标题:开始使用Go Modules
本文链接:https://blog.frognew.com/2019/03/touch-go-modules.html
转载请注明出处。

目录