英文:
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 (
"github.com/heroku/log-shuttle"
"fmt"
"log"
)
...
Great. But now I go to go build
and...
$ go build
# github.com/<my project>
logWriter/log_shuttle_writer.go:5: can't find import: "github.com/heroku/log-shuttle"
I have my GOPATH
set correctly (I believe):
$ 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"
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论