'go mod init example.com/m' to initialize a v0 or v1 module

huangapple go评论95阅读模式
英文:

'go mod init example.com/m' to initialize a v0 or v1 module

问题

我正在学习https://youtu.be/ma7rUS_vW9M?t=73

视频

'go mod init example.com/m' to initialize a v0 or v1 module

我的环境

'go mod init example.com/m' to initialize a v0 or v1 module

D:\temp2023_03_01\go\src>go version
go version go1.20.1 windows/amd64

我的操作

Microsoft Windows [版本 10.0.22621.1265]
(c) Microsoft Corporation。保留所有权利。

D:\temp2023_03_01\go\src\github.com\robbyklein\go-jwt>go mod init
go: 无法确定源目录 D:\temp2023_03_01\go\src\github.com\robbyklein\go-jwt 的模块路径(在 GOPATH 之外,必须指定模块路径)

示例用法:
        'go mod init example.com/m' 以初始化 v0 或 v1 模块
        'go mod init example.com/m/v2' 以初始化 v2 模块

运行 'go help mod init' 以获取更多信息。

D:\temp2023_03_01\go\src\github.com\robbyklein\go-jwt>

'go mod init example.com/m' to initialize a v0 or v1 module

为什么我的结果与视频不同?我应该怎么做才能达到视频中的结果?

英文:

I am learning at https://youtu.be/ma7rUS_vW9M?t=73

Video

'go mod init example.com/m' to initialize a v0 or v1 module

My environment

'go mod init example.com/m' to initialize a v0 or v1 module

D:\temp2023_03_01\go\src>go version
go version go1.20.1 windows/amd64

My actions

Microsoft Windows [Version 10.0.22621.1265]
(c) Microsoft Corporation. All rights reserved.

D:\temp2023_03_01\go\src\github.com\robbyklein\go-jwt>go mod init
go: cannot determine module path for source directory D:\temp2023_03_01\go\src\github.com\robbyklein\go-jwt (outside GOPATH, module path must be specified)

Example usage:
        'go mod init example.com/m' to initialize a v0 or v1 module
        'go mod init example.com/m/v2' to initialize a v2 module

Run 'go help mod init' for more information.

D:\temp2023_03_01\go\src\github.com\robbyklein\go-jwt>

'go mod init example.com/m' to initialize a v0 or v1 module

Why my result is different with video? What I do for archive result like the video?

答案1

得分: 2

https://pkg.go.dev/cmd/go#hdr-Initialize_new_module_in_current_directory

> Init函数接受一个可选参数,即新模块的模块路径。如果省略模块路径参数,init函数将尝试使用.go文件中的导入注释、供应工具配置文件(如Gopkg.lock)和当前目录(如果在GOPATH中)来推断模块路径。

你的GOPATH设置为D:\vygopath,但你要运行go mod init的项目位于D:\temp2023_03_01\go\src。如果你想让go mod init在没有模块路径的情况下工作,你应该将项目移动到D:\vygopath\src。之后,go mod init命令应该可以工作,工具应该能够推断出模块路径。

'go mod init example.com/m' to initialize a v0 or v1 module

英文:

https://pkg.go.dev/cmd/go#hdr-Initialize_new_module_in_current_directory

> Init accepts one optional argument, the module path for the new module. If the module path argument is omitted, init will attempt to infer the module path using import comments in .go files, vendoring tool configuration files (like Gopkg.lock), and the current directory (if in GOPATH).

Your GOPATH is set to D:\vygopath but the project for which you are running go mod init is located in D:\temp2023_03_01\go\src. If you want go mod init to work without module-path then you should move the project over to D:\vygopath\src instead. After that the go mod init command should work, the tool should be able to infer the module-path.

'go mod init example.com/m' to initialize a v0 or v1 module

答案2

得分: 0

D:\temp2023_03_01\go\src>go mod init github.com/robbyklein/go-jwt
go: 正在创建新的 go.mod 文件: module github.com/robbyklein/go-jwt

英文:
D:\temp2023_03_01\go\src>go mod init github.com/robbyklein/go-jwt
go: creating new go.mod: module github.com/robbyklein/go-jwt

huangapple
  • 本文由 发表于 2023年3月1日 23:17:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75605661.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定