go版本为go 1.16
在使用命令:go mod init 时,报如下错误

go: cannot determine module path for source directory D:\go\code\SipSvrProxy\src\Common (outside GOPATH, module path must be specified)


之前网上查询了好多方式,都不管用了,最终在 https://golang.google.cn/project 找到相关文档

进来后,我们找到Tools->Go command->Modules下有如下描述:

Module-aware mode is enabled by default, regardless of whether a go.mod file is present in the current working directory or a parent directory. More precisely, the GO111MODULE environment variable now defaults to on. To switch to the previous behavior, set GO111MODULE to auto.

Build commands like go build and go test no longer modify go.mod and go.sum by default. Instead, they report an error if a module requirement or checksum needs to be added or updated (as if the -mod=readonly flag were used). Module requirements and sums may be adjusted with go mod tidy or go get.

go install now accepts arguments with version suffixes (for example, go install example.com/cmd@v1.0.0). This causes go install to build and install packages in module-aware mode, ignoring the go.mod file in the current directory or any parent directory, if there is one. This is useful for installing executables without affecting the dependencies of the main module.

go install, with or without a version suffix (as described above), is now the recommended way to build and install packages in module mode. go get should be used with the -d flag to adjust the current module’s dependencies without building packages, and use of go get to build and install packages is deprecated. In a future release, the -d flag will always be enabled.

retract directives may now be used in a go.mod file to indicate that certain published versions of the module should not be used by other modules. A module author may retract a version after a severe problem is discovered or if the version was published unintentionally.
The go mod vendor and go mod tidy subcommands now accept the -e flag, which instructs them to proceed despite errors in resolving missing packages.

The go command now ignores requirements on module versions excluded by exclude directives in the main module. Previously, the go command used the next version higher than an excluded version, but that version could change over time, resulting in non-reproducible builds.

In module mode, the go command now disallows import paths that include non-ASCII characters or path elements with a leading dot character (.). Module paths with these characters were already disallowed (see Module paths and versions), so this change affects only paths within module subdirectories.

google翻译出来就是:

Module-aware模式默认启用,无论 go.mod 文件是否存在于当前工作目录或父目录中。更准确地说,GO111MODULE 环境变量现在默认为 on。要切换到之前的行为,请将 GO111MODULE 设置为 auto。

默认情况下,像 go build 和 go test 这样的构建命令不再修改 go.mod 和 go.sum。相反,如果需要添加或更新模块要求或校验和,它们会报告错误(就像使用了 -mod=readonly 标志一样)。模块要求和总和可以通过 go mod tidy 或 go get 进行调整。

go install 现在接受带有版本后缀的参数(例如,go install example.com/cmd@v1.0.0)。这会导致 go install 以模块感知模式构建和安装包,忽略当前目录或任何父目录中的 go.mod 文件(如果有)。这对于在不影响主模块的依赖关系的情况下安装可执行文件很有用。

go install,带或不带版本后缀(如上所述),现在是在模块模式下构建和安装包的推荐方式。 go get 应该与 -d 标志一起使用来调整当前模块的依赖项,而无需构建包,并且不推荐使用 go get 来构建和安装包。在未来的版本中, -d 标志将始终启用。

现在可以在 go.mod 文件中使用收回指令来指示模块的某些已发布版本不应被其他模块使用。模块作者可能会在发现严重问题或无意发布版本后撤回版本。

go mod vendor 和 go mod tidy 子命令现在接受 -e 标志,该标志指示它们尽管在解析丢失的包时出错,仍继续进行。

go 命令现在忽略对主模块中的 exclude 指令排除的模块版本的要求。以前,go 命令使用比排除版本更高的下一个版本,但该版本可能会随着时间的推移而改变,从而导致不可重现的构建。

在模块模式下,go 命令现在不允许包含非 ASCII 字符或带有前导点字符 (.) 的路径元素的导入路径。带有这些字符的模块路径已被禁止(请参阅模块路径和版本),因此此更改仅影响模块子目录中的路径。

go mod 某些命令,需要带参数,否则要报错。
使用示例:

go mod init Common

输出:

go: creating new go.mod: module Common
go: to add module requirements and sums:go mod tidy


此时再使用其他go mod命令就不会报错了。
如:

go mod tidy

golang使用go Modules相关命令时报错相关推荐

  1. 执行ldapadd 命令时报错:ldap_bind: Invalid credentials (49)

    转载自:http://www.linuxfly.org/post/671/ 某项目,需要在Asianux 4.0上配置LDAP服务.参考以前的[原]操作ldap 数据库一文,在执行ldapadd 命令 ...

  2. mysql grant reload,MySQL执行GRANT命令时报错ERROR 1045解决办法

    摘要 腾兴网为您分享:MySQL执行GRANT命令时报错ERROR 1045解决办法,杂志迷,云闪付,一直播,小象优品等软件知识,以及592美剧,乐天网络电视,吃鸡无后座,易语言宝盒,语音转文字软件, ...

  3. linux怎么卸载webpack,安装webpack后,执行webpack -v命令时报错:SyntaxError: Block-sc

    安装webpack后,执行webpack -v命令时报错如下: [root@FreeServer ~]# webpack -v /usr/local/node-v4.4.7-linux-x64/lib ...

  4. 【Cmake】执行cmake命令时报错:No XSLT processor found

    一.问题描述 在ubuntu中,在生成Doc(文档)中,执行cmake命令时报错:No XSLT processor found 二.原因查找 google该错误信息,原因是确实ubuntu中没有安装 ...

  5. fabric生成交易相关文件时报错

    我执行一下命令时报错 configtxgen -profile OneOrgOrdererGenesis -channelID byfn-sys-channel -outputBlock ./chan ...

  6. 运行yum install -y mssql-server命令时报错:

    运行yum install -y mssql-server命令时报错:Loaded plugins: fastestmirror File contains no section headers. f ...

  7. 使用yum命令时报错Cannot retrieve metalink for repository epel

    使用yum命令时报错Cannot retrieve metalink for repository epel 问题背景 问题分析 问题处理 问题背景 通过Yum安装ftp时报如下错误: $ yum s ...

  8. linux下使用find命令时报错“find: paths must precede expression”

    问题: linux下使用find命令时报错"find: paths must precede expression" find / -name xxx* 解决办法: 通配符两边加单 ...

  9. 执行wsl 命令时报错 nsenter: failed to execute 564: No such file or directory

    问题 在cmd命令框中执行wsl命令时报错 nsenter: failed to execute 564: No such file or directory无法进入Ubuntu子系统中 C:\Use ...

  10. 命令行运行命令时报错You don#39;t have write permissions for the /Library/***

    这是由于要运行这些操作时必须有管理员的权限(比方更新软件),比方更新cocoapods时报错 soindy:SmartThermo soindy$ gem install cocoapods Fetc ...

最新文章

  1. [HNOI2008] Cards
  2. string s.substr()的用法
  3. Python:正则表达式
  4. Zookeper znode 4种类型 是什么?
  5. Windows Print Spooler服务最新漏洞CVE-2021-34527详解
  6. C#语言: 生成静态页面核心代码
  7. 130. 被围绕的区域
  8. Lazyload 延迟加载效果(转载)
  9. 数据库实战:SQL Server系列网络课程资料集
  10. 计算机桌面左侧在显示器里面,电脑屏幕显示偏左怎么解决
  11. UltraLAB台式图形工作站(图形+超算+私有云通吃~图灵超算工作站介绍)
  12. log日志中不打印异常栈的具体信息
  13. python涨跌柱表行业市盈率
  14. 来自CSDN或其它的精华网址
  15. 转载: React Native 采用Fetch方式发送跨域POST请求
  16. Android SoundPool插入耳机后依然有外放声音
  17. GSM模块的GPRS的TCP测试成功-校园网(内网穿透)映射
  18. python+ddt
  19. 佳能Canon imageRUNNER ADVANCE C5535 驱动
  20. plc的应用领域有哪些

热门文章

  1. 32位x86处理器编程架构
  2. 训练CV模型新思路来了:用NLP大火的Prompt替代微调,性能全面提升
  3. win10便签常驻桌面_Win10下环境有哪些好用的便签记事本?想和iPhone一块儿用 - 学显...
  4. 设计模式学习专栏六--------适配器模式
  5. codewars练习(javascript)-2021/2/24
  6. 京东VC后台自动批量上传主图 大聪明自动传主图 c# selenium网页自动化传图
  7. Java中数字转中文数字
  8. Spring配置文件中的parent与abstract
  9. 基于 H5 Canvas “指纹识别“ 技术 【浏览器指纹 VS Canvas指纹】
  10. MATLAB统计分析—描述性统计