英文:
Import path with colons in Golang
问题
我有一个本地私有仓库(gitlab),主机名为https://git.local.com:1234/
我的golang项目中有几个包
项目结构如下:
// my_project/main.go
package main
import (
"git.local.com:1234/my_project/notMainPackage"
)
func main() {
//....
}
// my_project/notMainPackage/notMainPackage.go
package notMainPackage
func SomeFunc() {
}
问题是,我应该在导入路径中使用冒号才能运行go get
和go build
命令,但是,当导入路径包含冒号时,我会得到错误
invalid import path: "git.local.com:1234/my_project/notMainPackage"
我不能更改gitlab服务器的主机。
我该如何解决这个问题?
英文:
I have local private repository (gitlab) with hostname https://git.local.com:1234/
Also I have several packages in my golang project
Project structure looks like:
// my_project/main.go
package main
import (
"git.local.com:1234/my_project/notMainPackage"
)
func main() {
//....
}
// my_project/notMainPackage/notMainPackage.go
package notMainPackage
func SomeFunc() {
}
The problem is that I should use colons in my import path to be able run go get
and go build
comands, but, when import path contains colon, I get error
invalid import path: "git.local.com:1234/my_project/notMainPackage"
I can't change host of gitlab sever.
How can i solve this problem?
答案1
得分: 2
根据评论中的建议,执行以下操作:
git clone git.local.com:1234/my_project/notMainPackage
这样,git项目就会加载到你的gopath中。
然后,按照以下方式使用它:
// my_project/main.go
package main
import (
"my_project/notMainPackage"
)
func main() {
//....
}
希望这对你有帮助!
英文:
As the suggestion in comment,
do
git clone git.local.com:1234/my_project/notMainPackage
so the git project loads on to your gopath and
just use it like below,
// my_project/main.go
package main
import (
"my_project/notMainPackage"
)
func main() {
//....
}
Hope this helps!!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论