如何使用Go远程导入路径指定端口? [英] How can I specify ports using Go remote import paths?
问题描述
因为我有一个私人(公司自己托管)的git仓库,它侦听另一个,但默认的http端口。 (例如6655)
完整的存储库URL到我的golang库是:
http://internal-git.corporate-domain.com:6655/~myuser/golang-lib.git
我试图像这样导入:
包主
导入(
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
无法加载p ackage:包myuser / golang-project:
main.go:7:2:无效导入路径:internal-git.corporate-domain.com:6655/~myuser/golang-lib.git
与以前的评论一样,您可能想要克隆 Git 存储库添加到您的 $ GOPATH
(%GOPATH%
for Windows )根据你的例子, clone
命令应该是这样的:
$ b
$ b
git clone internal-git.corporate-domain.com:6655/~myuser/golang-lib.git $ GOPATH / corporate-domain.com / golang-lib
您在 Go 源文件中的导入内容如下所示:
导入corporate-domain.com/golang-lib
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"
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"
这篇关于如何使用Go远程导入路径指定端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!