douqin1932
2019-08-18 15:43
浏览 71
已采纳

无法在全新的Go项目中加载软件包

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

GOBIN="/home/x80486/Workshop/go/bin/"
GOPATH="/home/x80486/Workshop/go/"
GOROOT="/home/x80486/.asdf/installs/golang/1.12.6/go/"

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 (
  "github.com/getgauge-contrib/gauge-go/gauge"
)

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

...and I ran go test:

[x80486@uplink gauge-basics]$ go test
go: finding github.com/getgauge-contrib/gauge-go/gauge latest
go: finding github.com/getgauge/common latest
go: finding github.com/golang/protobuf/proto latest
go: finding github.com/dmotylev/goproperties latest
?       github.com/x80486/gauge-basics  [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 github.com/x80486/gauge-basics: unknown import path "github.com/x80486/gauge-basics": cannot find module providing package github.com/x80486/gauge-basics

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:

module github.com/x80486/gauge-basics

go 1.12

require (
    github.com/dmotylev/goproperties v0.0.0-20140630191356-7cbffbaada47 // indirect
    github.com/getgauge-contrib/gauge-go v0.1.3 // indirect
    github.com/getgauge/common v0.0.0-20190514095629-619e107433ce // indirect
    github.com/golang/protobuf 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 
 
import(  
“ github.com/getgauge-contrib/gauge-go/gauge"
)

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

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

  [x80486 @ uplink gauge-basics] $进行测试
go:查找github.com/getgauge-contrib/gauge-go/gauge Latest 
go:查找github.com/getgauge/common最新
go:查找github.com/  golang / protobuf / proto最新
go:找到github.com/dmotylev/goproperties最新
?  github.com/x80486/gauge-basics [无测试文件] 
 </ code> </ pre> 
 
 

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

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

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


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

 模块github.com/x80486/gauge-basics

go 1.12 
 
require(
  github.com/dmotylev/goproperties v0.0.0-20140630191356-7cbffbaada47 //间接
 github.com/getgauge-contrib/gauge-go v0.1.3 //间接
 github.com/getgauge/common v0.0.0-20190514095629  -619e107433ce //间接
 github.com/golang/protobuf v1.3.2 //间接 
)
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题