How to use custom package with glide

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

How to use custom package with glide

问题

我使用golang的Masterminds/glide来管理包。这是我的项目结构:

  1. $GOPATH/
  2. bin/
  3. pkg/
  4. src/
  5. go_test/
  6. long(自定义包:只打印“hello”)
  7. main.go
  8. glide.yaml
  9. vendor/
  10. github.com/lib/pq

在main.go中使用了long包:

  1. package main
  2. import (
  3. "database/sql"
  4. "github.com/lib/pq"
  5. "long"
  6. )
  7. func main() {
  8. // ...
  9. }

glide.yaml文件内容如下:

  1. package: go_test
  2. import:
  3. - package: github.com/lib/pq

当运行go run main.go时,会出现找不到long包的错误。如果将long包放入vendor/目录中,然后运行glide up,会显示无法检测到关于"long"依赖的版本控制系统(VCS),但是可以正常运行项目。因此,我想知道如何设置glide以跳过对long包的检测,使项目能够正常运行。

注意:我在yaml文件中使用了ignore字段。如果将long添加到ignore中,项目将能够运行,但无法找到long包。

英文:

I use golang Masterminds/glide to manage package. here is my project:

  1. $GOPATH/
  2. bin/
  3. pkg/
  4. src/
  5. go_test/
  6. long(own custom package: just print a "hello")
  7. main.go
  8. glide.yaml
  9. vendor/
  10. github.com/lib/pq

the long package is used in main.go like :

  1. package main
  2. import(
  3. "database/sql"
  4. "github.com/lib/pq"
  5. "long"
  6. )
  7. func main(
  8. ...
  9. }

the glide.yaml is:

  1. package: go_test
  2. import:
  3. - package: github.com/lib/pq

  when go run main.go the error is: can not found package long .
if I put the long package into the vendor/ and then glide up
 it will show can not detect vcs about the "long" dependencies. but can run with project.
 so I want to know how to set that glide will skip the long package detect and the project can run .

note: I use the ignore: in the yaml. if add long to ignore .the project will can run because can't find long package.

答案1

得分: 0

因为正确的包名是从你的项目中的/src目录开始的完整路径,所以在你的import语句中应该使用"go_test/long"而不是只用"long"。而且,由于这是你自己的代码而不是供应商的依赖项,它不能放在vendor目录下。

英文:

Because the correct package name is a full path starting from /src directory in you project you should use "go_test/long" instead on just "long" in you import statement. And because it is your own code and not a vendor dependency it must not be under vendor directory.

huangapple
  • 本文由 发表于 2017年7月31日 16:06:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/45410422.html
匿名

发表评论

匿名网友

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

确定