Golang 1.11beta2 introduced experimental support for Modules.
I am failing to import a specific package from a go module.
This is the error when building the application:
$ go install
go: downloading github.com/udhos/modhello/modlib/lib v1.0.0
go: finding github.com/udhos/modhello latest
go: import "github.com/udhos/modhello/modapp" ->
import "github.com/udhos/modhello/modlib/lib": cannot find module providing package github.com/udhos/modhello/modlib/lib
Why is the import shown above failing?
This is the package 'lib' from module 'modlib':
# repo: modhello
# module: modlib
# package: lib
$ cat modhello/modlib/lib/modlib.go
package lib
func Sum(a, b int) int {
return a + b
}
$ cat modhello/modlib/go.mod
module github.com/udhos/modhello/modlib
This is the application 'modapp' :
$ cat modhello/modapp/main.go
package main
import (
"log"
"github.com/udhos/modhello/modlib/lib"
)
func main() {
run(1, 2)
}
func run(a, b int) {
log.Printf("Sum(%d,%d) = %d", a, b, lib.Sum(a, b))
}
$ cat modhello/modapp/go.mod
module github.com/udhos/modhello/modapp
require github.com/udhos/modhello/modlib v1.0.0
The git repository is tagged with 'modlib/v1.0.0'. This is how one publishes a version for a module.
Go version:
$ go version
go version go1.11beta2 linux/amd64
$ git --version
git version 2.18.0
I have posted this doubt also on golang-nuts: Host two distinct modules in one git repo?