导入路径不以主机名开头

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

(import path does not begin with hostname)

问题

我的demo golang项目是https://github.com/aQuaYi/demoGolangProjectWithCI

demoGolangProjectWithCI/subModel/subModelAdd.go文件内容如下:

package subModel

import (
    "demoGolangProjectWithCI"
)

// Add函数返回a和b的和
func Add(a, b int) int {
    return demoGolangProjectWithCI.Add(a, b)
}

我的.travis.yml文件内容如下:

language: go

go:
  - 1.8.3

script: go test ./...

但是travis告诉我:"package demoGolangProjectWithCI: unrecognized import path "demoGolangProjectWithCI" (import path does not begin with hostname)"

详细信息请参考:https://travis-ci.org/aQuaYi/demoGolangProjectWithCI/builds/247416861

我该如何解决这个问题?

非常感谢。

英文:

My demo golang project is https://github.com/aQuaYi/demoGolangProjectWithCI

demoGolangProjectWithCI/subModel/subModelAdd.go is

package subModel

import (
    "demoGolangProjectWithCI"
)

//Add returns sum of a and b
func Add(a, b int) int {
    return demoGolangProjectWithCI.Add(a, b)
}

and my .travis.yml is

language: go

go:
  - 1.8.3

script: go test ./...

but travis said me "package demoGolangProjectWithCI: unrecognized import path "demoGolangProjectWithCI" (import path does not begin with hostname)"

detail is https://travis-ci.org/aQuaYi/demoGolangProjectWithCI/builds/247416861

How Could I fix this?

Thank you very much.

答案1

得分: 2

demoGolangProjectWithCI无法从subModel中解析,因为导入"demoGolangProjectWithCI"表示绝对路径。你可以使用相对路径来写,例如./demoGolangProjectWithCI。但是通常情况下,最好使用完整的GitHub路径,例如github.com/aQuaYi/demoGolangProject,因为你的包可能会被其他项目使用。

英文:

demoGolangProjectWithCI is not resolved from subModel because import "demoGolangProjectWithCI" mean absolute path. You can write relative path like ./demoGolangProjectWithCI. But, in generally, you've better to write full-github-paths as github.com/aQuaYi/demoGolangProject since your package may be used by other one's project.

huangapple
  • 本文由 发表于 2017年6月27日 16:16:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/44775337.html
匿名

发表评论

匿名网友

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

确定