2019-08-18 15:43
浏览 71


I'm trying modules in Go. I'm outside the GOPATH and using version 1.12.6:


I created a new project and initialized it as a module inside: /home/x80486/Workshop/Development/gauge-basics. I then created a file example_spec.go with this content:

package stepImpl

import (

var _ = gauge.Step("Run me before any other", func() {})

...and I ran go test:

[x80486@uplink gauge-basics]$ go test
go: finding latest
go: finding latest
go: finding latest
go: finding latest
?  [no test files]

Everything is somehow OK, but as soon as I move this file into a folder named stepImpl, nothing works:

[x80486@uplink gauge-basics]$ go build
can't load package: package unknown import path "": cannot find module providing package

I can't understand why moving a file to a folder with the package name would break the project.

This is the generated go.mod file:


go 1.12

require ( v0.0.0-20140630191356-7cbffbaada47 // indirect v0.1.3 // indirect v0.0.0-20190514095629-619e107433ce // indirect v1.3.2 // indirect

图片转代码服务由CSDN问答提供 功能建议

我正在尝试Go中的模块。 我在 GOPATH </ code>之外,并使用版本 1.12.6 </ code>:</ p>

  GOBIN = “/家/ x80486 /车间/去/斌/” 
GOPATH = “/家/ x80486 /车间/去/” 
GOROOT =“/家/ x80486 / .asdf /安装/ golang / 1.12.6 /  go /“ 
 </ code> </ pre> 

我创建了一个新项目,并将其初始化为内部模块: / home / x80486 / Workshop / Development / gauge-basics </ 代码>。 然后,我用以下内容创建了文件 example_spec.go </ code>:</ p>

  package stepImpl 

var _ = gauge.Step(“先跑我跑”,func(){})
 </ code>  </ pre> 

...然后我运行了 go test </ code>:</ p>

  [x80486 @ uplink gauge-basics] $进行测试
go:查找 Latest 
go:查找  golang / protobuf / proto最新
? [无测试文件] 
 </ code> </ pre> 

一切正常,但是只要我将此文件移动到名为的文件夹中 > stepImpl </ code>,什么都行不通:</ p>

  [x80486 @ uplink gauge-basics] $ go build 
无法加载 软件包:软件包未知的导入路径“”:找不到提供软件包
 </ code>的模块</  pre> 

我不明白为什么将文件移动到带有程序包名称的文件夹会破坏项目。</ p>

这是 生成的 go.mod </ code>文件:</ p>


go 1.12 
require( v0.0.0-20140630191356-7cbffbaada47 //间接 v0.1.3 //间接 v0.0.0-20190514095629  -619e107433ce //间接 v1.3.2 //间接 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题