ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

go mod 使用

2021-04-16 15:01:15  阅读:204  来源: 互联网

标签:GOPATH GO111MODULE modules module 使用 go mod


前言

go version 需高于1.11

  1. 配置环境变量
go env

GO111MODULE=on
GOPROXY=https://goproxy.cn,direct
GOSUMDB=off
  • 修改GO111MODULE

    • GO111MODULE 有三个值:off, on和auto(默认值)。

    • GO111MODULE=off

      go命令行将不会支持module功能,寻找依赖包的方式将会沿用旧版本那种通过vendor目录或者GOPATH模式来查找。

    • GO111MODULE=on

      go命令行会使用modules,而一点也不会去GOPATH目录下查找。

    • GO111MODULE=auto

      默认值,go命令行将会根据当前目录来决定是否启用module功能。这种情况下可以分为两种情形:

  当前目录在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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有