简体   繁体   English

在Golang中用冒号导入路径

[英]Import path with colons in Golang

I have local private repository (gitlab) with hostname https://git.local.com:1234/ 我有主机名称为https://git.local.com:1234/的本地专用存储库(gitlab)

Also I have several packages in my golang project 我的golang项目中也有几个软件包

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 问题是我应该在导入路径中使用冒号才能运行go getgo build comands,但是,当导入路径包含冒号时,我会报错

invalid import path: "git.local.com:1234/my_project/notMainPackage"

I can't change host of gitlab sever. 我无法更改gitlab服务器的主机。

How can i solve this problem? 我怎么解决这个问题?

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 所以git项目加载到您的gopath上,

just use it like below, 像下面这样使用

// my_project/main.go
package main

import (
    "my_project/notMainPackage"
)

func main() {
    //....
}

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM