如何使用Go远程导入路径指定端口?

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

How can I specify ports using Go remote import paths?

问题

给定我有一个私有的(企业自托管的)git仓库,它监听在另一个非默认的http端口上(例如6655)。

我的golang库的完整仓库URL是:

http://internal-git.corporate-domain.com:6655/~myuser/golang-lib.git

我尝试这样导入:

package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
	"log"
	"net/http"
	"os"
	"os/signal"
	"time"
)

这里这里的文档对此并不明确。

当我尝试编译上述代码时,我得到以下错误:

C:\Users\myuser\gopath\src\myuser\golang-project>go get
can't load package: package myuser/golang-project:
main.go:7:2: invalid import path: "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
英文:

given I have a private (corporate self-hosted) git repository which listens on on another but the default http-port. (For example 6655)

The full repository-url to my golang-library would be:

http://internal-git.corporate-domain.com:6655/~myuser/golang-lib.git

I tried importing this like so:

package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"
	"log"
	"net/http"
	"os"
	"os/signal"
	"time"

)

Documentation here and here is not explicit about that.

When I try to compile the code above I get:

C:\Users\myuser\gopath\src\myuser\golang-project>go get
can't load package: package myuser/golang-project:
main.go:7:2: invalid import path: "internal-git.corporate-domain.com:6655/~myuser/golang-lib.git"

答案1

得分: 4

另一种解决方案是修改你的 .gitconfig 文件以适应端口。

insteadOf = git://internal-git.corporate-domain.com
英文:

Another solution is to change your .gitconfig to work with ports.

insteadOf = git://internal-git.corporate-domain.com

答案2

得分: 2

根据之前的评论,你可能想要将Git仓库克隆到你的$GOPATHWindows下为%GOPATH%)目录中。

根据你的示例,clone命令应该是这样的:

git clone internal-git.corporate-domain.com:6655/~myuser/golang-lib.git $GOPATH/corporate-domain.com/golang-lib

Go源文件中,你的导入语句应该是这样的:

import "corporate-domain.com/golang-lib"
英文:

Like a previous comment said you probably want to clone the Git repository into your $GOPATH (%GOPATH% for Windows) directory.

Per your example the clone command would look like:

git clone internal-git.corporate-domain.com:6655/~myuser/golang-lib.git $GOPATH/corporate-domain.com/golang-lib

And your import in Go source files would look like:

import "corporate-domain.com/golang-lib"

huangapple
  • 本文由 发表于 2016年1月21日 19:45:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/34922929.html
匿名

发表评论

匿名网友

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

确定