英文:
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仓库克隆到你的$GOPATH
(Windows下为%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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论