This code works as long as I'm on the master
branch:
main.go:
package main
import (
datemodlocal "192.168.0.12/gitrepo/go-module-test-dateutil.git"
stringmodlocal "192.168.0.12/gitrepo/go-module-test-stringutil.git"
"fmt"
"github.com/dwschulze/go-module-test-dateutilmod"
"github.com/dwschulze/go-module-test-stringutilmod"
)
func main() {
fmt.Println("github: " + stringmod.ToUpperCase("test"))
fmt.Println("github: " + datemod.GetTime().String())
fmt.Println("local: " + stringmodlocal.ToUpperCase("test"))
fmt.Println("local: " + datemodlocal.GetTime().String())
}
go.mod:
module module-driver
require (
192.168.0.12/gitrepo/go-module-test-dateutil.git v0.0.1
192.168.0.12/gitrepo/go-module-test-stringutil.git v0.0.1
github.com/dwschulze/go-module-test-dateutilmod v0.0.1
github.com/dwschulze/go-module-test-stringutilmod v0.0.1
)
go 1.15
I need to use the branch dev2
for development. The godocs don't show what needs to be done to the import path or the require statement in go.mod
. If I change the import statement to:
datemodlocal "192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2"
I get:
$ go run main.go
package command-line-arguments
imports 192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2: can only use path@version syntax with go get
If I move the @dev2
to the require statement in go.mod
192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2 v0.0.1
I get
$ go run main.go
go: 192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2@v0.0.1: unrecognized import path "192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2": https fetch: Get "https://192.168.0.12/gitrepo/go-module-test-dateutil.git@dev2?go-get=1": dial tcp 192.168.0.12:443: connect: connection refused
That error message says https
which is strange since in my ~/.gitconfig
I have
[url "dean@192.168.0.12:"] insteadOf = https://192.168.0.12/
Setting GOPRIVATE
has no effect. If I put the @dev2
in both places I get the same error messages.
The godocs don't show any examples of what a working .go
and go.mod
file would have to contain to use modules on a branch other than master
. I would think that modules would have to work on any branch because development is often done on branches other than master
.
Does anyone have a working example of a .go
file and a go.mod
that work on a branch other than master?