在Golang中导入带有冒号的路径。

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

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 getgo 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!!

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

发表评论

匿名网友

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

确定