无法找到导入项

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

Go 'Can't Find Import'

问题

我正在尝试将Heroku的log-shuttle库(https://github.com/heroku/log-shuttle)整合到我正在开发的Go项目中。该工具主要设计为独立的二进制文件运行,但我希望以不同的方式将其集成到我的工具中。

首先,我获取了该库:

$ go get github.com/heroku/log-shuttle
$ ls $GOPATH/src/github.com/heroku/log-shuttle/
  batcher.go       Godeps ...
  ...

这一步返回成功。然后我尝试导入该库:

package myPackage

import (
  "github.com/heroku/log-shuttle"
  "fmt"
  "log"
)
...

很好。但是现在我执行go build命令...

$ go build
# github.com/<my project>
logWriter/log_shuttle_writer.go:5: 找不到导入: "github.com/heroku/log-shuttle"

我已经正确设置了GOPATH(我相信):

$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jeff/go/"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"

该包已安装和构建,但是它不想被导入。如你所见,包路径中没有非ASCII字符(虽然连字符是非字母数字字符),我找不到有关可能导致此问题的更多信息。

不确定它是否重要,但我正在尝试使用godep来管理我的依赖项。

提前感谢您的帮助。

英文:

I'm attempting to incorporate Heroku's log-shuttle library (https://github.com/heroku/log-shuttle) into a Go project I'm working on. The tool is primarily designed to be run as an independent binary, but I'm hoping to integrate it in a different way in my tool.

So I get the library:

$ go get github.com/heroku/log-shuttle
$ ls $GOPATH/src/github.com/heroku/log-shuttle/
  batcher.go       Godeps ...
  ...

which returns successfully. Then I try to import the library:

package myPackage

import (
  &quot;github.com/heroku/log-shuttle&quot;
  &quot;fmt&quot;
  &quot;log&quot;
)
...

Great. But now I go to go build and...

$ go build
# github.com/&lt;my project&gt;
logWriter/log_shuttle_writer.go:5: can&#39;t find import: &quot;github.com/heroku/log-shuttle&quot;

I have my GOPATH set correctly (I believe):

$ go env
GOARCH=&quot;amd64&quot;
GOBIN=&quot;&quot;
GOCHAR=&quot;6&quot;
GOEXE=&quot;&quot;
GOHOSTARCH=&quot;amd64&quot;
GOHOSTOS=&quot;linux&quot;
GOOS=&quot;linux&quot;
GOPATH=&quot;/home/jeff/go/&quot;
GORACE=&quot;&quot;
GOROOT=&quot;/usr/lib/go&quot;
GOTOOLDIR=&quot;/usr/lib/go/pkg/tool/linux_amd64&quot;
TERM=&quot;dumb&quot;
CC=&quot;gcc&quot;
GOGCCFLAGS=&quot;-g -O2 -fPIC -m64 -pthread&quot;
CXX=&quot;g++&quot;
CGO_ENABLED=&quot;1&quot;

And the package is installed and built, but it doesn't want to import. As you can see, there are non non-ASCII chars in the package path (though the hyphen is non-alpha-numeric), and I can't find any more info about what could be causing this problem.

Not sure how it would matter, but I am using godep to try to manage my dependencies.

Thanks in advance.

答案1

得分: 6

github.com/heroku/log-shuttle 是一个 main 包,而不是一个可导入的库,这意味着它是用于编译和运行二进制文件的。

英文:

github.com/heroku/log-shuttle is a main package, not an importable library, meaning it's meant to be compiled and run as a binary.

huangapple
  • 本文由 发表于 2014年7月16日 04:36:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/24767707.html
匿名

发表评论

匿名网友

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

确定