英文:
(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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论