其他分享
首页 > 其他分享> > go mod 使用

go mod 使用

作者:互联网

前言

go version 需高于1.11

  1. 配置环境变量
go env

GO111MODULE=on
GOPROXY=https://goproxy.cn,direct
GOSUMDB=off
  当前目录在GOPATH/src之外且该目录包含go.mod文件
  当前文件在包含go.mod文件的目录下面。

当modules功能启用时,依赖包的存放位置变更为$GOPATH/pkg,允许同一个package多个版本并存,且多个项目可以共享缓存的 module

  1. go mod命令

golang 提供了 go mod命令来管理包。

go help 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(编辑go.mod)
    graph       print module requirement graph (打印模块依赖图)
    init        initialize new module in current directory(在当前目录初始化mod)
    tidy        add missing and remove unused modules (拉取缺少的模块,移除不用的模块) 
    vendor      make vendored copy of dependencies (将依赖复制到vendor下)   
    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.

标签:GOPATH,GO111MODULE,modules,module,使用,go,mod
来源: https://blog.csdn.net/zhangkaiadl/article/details/115760138