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

无法在全新的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
)
  • 写回答

1条回答 默认 最新

  • dongtuoji5396 2019-08-18 15:55
    关注

    There are no .go files under github.com/x80486/gauge-basics, because you moved them under a different directory. You can run go build under the directory containing the source files or add another .go in the gauge-basics directory importing them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog