go mod init 在初始化时出现 cannot determine module path for source directory (outside GOPATH

问题:

新创建的golang项目,使用 go mod init 命令时出现 cannot determine module path for source directory xxxxxxx (outside GOPATH, module path must be specified)

解决方案:

这是因为go mod init 初始化项目时,需要定义一个 module ,我们打开一个 go.mod 文件,就会发现第一行就有

module ProjectName

因此,在执行 go mod init 时需要定义 module,如:

go mod init ProjectName
  • 29
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Chapter 1, Getting Started Sets the stage for the book by covering where you can find the tools used in the book, VBScript and PowerShell issues to consider, and where to find additional information. Chapter 2, Forests, Domains, and Trusts Covers how to create and remove forests and domains, update the domain mode or functional levels, create different types of trusts, and other administrative trust tasks. Chapter 3, Domain Controllers, Global Catalogs, and FSMOs Covers promoting and demoting domain controllers, finding domain controllers, enabling the global catalog, and finding and managing Flexible Single Master Operations (FSMO) roles. This will include coverage of the new Read-Only Domain Controller (RODC) that was introduced with Windows Server 2008. Chapter 4, Searching and Manipulating Objects Covers the basics of searching Active Directory: creating, modifying, and deleting objects, using LDAP controls, and importing and exporting data using LDAP Data Interchange Format (LDIF) and comma-separated variable (CSV) files. Chapter 5, Organizational Units Covers creating, moving, and deleting Organizational Units, and managing the objects contained within them. Chapter 6, Users Covers all aspects of managing user objects, including creating, renaming, moving, resetting passwords, unlocking, modifying the profile attributes, and locating users that have certain criteria (e.g., password is about to expire). This chapter includes coverage of the new Fine-Grained Password Policy feature that was introduced in Windows Server 2008. Chapter 7, Groups Covers how to create groups, modify group scope and type, and manage membership. Chapter 8, Computer Objects Covers creating computers, joining computers to a domain, resetting computers, and locating computers that match certain criteria (e.g., have been inactive for a number of weeks). Chapter 9, Group Policy Objects Covers how to create, modify, link, copy, import, back up, restore, and delete GPOs using the Group Policy
官方下载到的go module文档 Table of Contents The "Quick Start" and "New Concepts" sections are particularly important for someone who is starting to work with modules. The "How to..." sections cover more details on mechanics. The largest quantity of content on this page is in the FAQs answering more specific questions; it can be worthwhile to at least skim the FAQ one-liners listed here. Quick Start Example Daily Workflow New Concepts Modules go.mod Version Selection Semantic Import Versioning How to Use Modules How to Install and Activate Module Support How to Define a Module How to Upgrade and Downgrade Dependencies How to Prepare for a Release (All Versions) How to Prepare for a Release (v2 or Higher) Publishing a Release Migrating to Modules Additional Resources Changes Since the Initial Vgo Proposal GitHub Issues FAQs How are versions marked as incompatible? When do I get old behavior vs. new module-based behavior? Why does installing a tool via 'go get' fail with error 'cannot find main module'? How can I track tool dependencies for a module? What is the status of module support in IDEs, editors and standard tools like goimports, gorename, etc.? FAQs — Additional Control What community tooling exists for working with modules? When should I use the 'replace' directive? Can I work entirely outside of VCS on my local filesystem? How do I use vendoring with modules? Is vendoring going away? Are there "always on" module repositories and enterprise proxies? Can I control when go.mod gets updated and when the go tools use the network to satisfy dependencies? How do I use modules with CI systems such as Travis or CircleCI? How do I download modules needed to build specific packages or tests? FAQs — go.mod and go.sum Why does 'go mod tidy' record indirect and test dependencies in my 'go.mod'? Is 'go.sum' a lock file? Why does 'go.sum' include information for module versions I am no longer using? Should I still add a 'go.mod' file if I do not have any dependencies? Should I commit my 'go.sum' file as well as my 'go.mod' file? FAQs — Semantic Import Versioning Why must major version numbers appear in import paths? Why are major versions v0, v1 omitted from import paths? What are some implications of tagging my project with major version v0, v1, or making breaking changes with v2+? Can a module consume a package that has not opted in to modules? Can a module consume a v2+ package that has not opted into modules? What does '+incompatible' mean? How are v2+ modules treated in a build if modules support is not enabled? How does "minimal module compatibility" work in 1.9.7+, 1.10.3+, and 1.11? What happens if I create a go.mod but do not apply semver tags to my repository? Can a module depend on a different version of itself? FAQs — Multi-Module Repositories What are multi-module repositories? Should I have multiple modules in a single repository? Is it possible to add a module to a multi-module repository? Is it possible to remove a module from a multi-module repository? Can a module depend on an internal/ in another? Can an additional go.mod exclude unnecessary content? Do modules have the equivalent of a .gitignore file? FAQs — Minimal Version Selection Won't minimal version selection keep developers from getting important updates? FAQs — Possible Problems What are some general things I can spot check if I am seeing a problem? What can I check if I am not seeing the expected version of a dependency? Why am I getting an error 'cannot find module providing package foo'? Why does 'go mod init' give the error 'cannot determine module path for source directory'? I have a problem with a complex dependency that has not opted in to modules. Can I use information from its current dependency manager? How can I resolve "parsing go.mod: unexpected module path" and "error loading module requirements" errors caused by a mismatch between import paths vs. declared module identity? Why does 'go build' require gcc, and why are prebuilt packages such as net/http not used? Do modules work with relative imports like import "./subdir"? Some needed files may not be present in populated vendor directory

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值