Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify ports using Go remote import paths?

Tags:

git

go

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 image 484
crushervx Avatar asked Jan 21 '16 11:01

crushervx


2 Answers

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

[url "[email protected]:6655"]
  insteadOf = git://internal-git.corporate-domain.com
like image 153
RockOnGom Avatar answered Nov 06 '22 22:11

RockOnGom


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"
like image 24
Josh Lubawy Avatar answered Nov 06 '22 21:11

Josh Lubawy