Hi,
I spend my day trying to build a new project in Go using the new Go module system.
I didn't succeed so I'm kind of upset because I never waste that much time for something that simple before.
The project : I try to use Go module only so no environment variable anywhere.
There are 1 library and 1 executable (both in Go) in 2 different local folders.
The library In /home/angryBoy/myLib :
- go.mod
- myLib.go
- otherPkg
|- otherPkg.go
go.mod :
module xxx/myLib
myLib.go : its package name is "myLib" and it doesn't import "otherPkg"
otherPkg.go : its package name is "otherPkg" and it does import "myLib"
At this point if I build it : "$ cd myLib && go build"
it's seems to be ok but in fact, it doesn't compile otherPkg.go (I add a compilation error inside to be sure)
1) Why doesn't it compile everthing like before ? How can I fix that ?
The executable In /home/angryBoy/myBin :
- go.mod
- myBin.go
go.mod :
module yyy/myBin
myBin.go : its package name is "myBin" and it does import "xxx/myLib" and "xxx/myLib/otherPkg"
But it fail at compilation ("$ cd myBin && go build") because it doesn't reconize "xxx/myLib". So, after a long time, I find something about "replace" keyword in go.mod so :
go.mod :
module yyy/myBin
require xxx/myLib v1.0.0
replace xxx/myLib => /home/angryBoy/myLib
And this workaround kind of works for this specific import but it doesn't work for otherPkg. Moreover, if I add :
require xxx/myLib/otherPkg v1.0.0
replace xxx/myLib/otherPkg => /home/angryBoy/myLib/otherPkg
It doesn't find the go.mod (of course there is not). But if I understand correctly it shouldn't have more than 1 go.mod in a repository.
2) Is the "replace" workaround the good way to allow local compilation ? If yes, how can I access my sub-package ?
Thanks in advance,