-2

My source directory layout like

mywork/libA
mywork/libA/liba.go
mywork/libA/go.mod
mywork/progB
mywork/progB/go.mod
mywork/progB/progb.go
  • In mywork/libA/ directory, I type go mod init example.com/mywork/liba.
  • In mywork/progB/ directory, I type go mod init example.com/mywork/progb.

libA/liba.go

package liba
func Hi() string {      return "hi" }

libA/go.mod

module example.com/mywork/liba

go 1.13

progB/progb.go

package main
import "example.com/mywork/liba"
func main() { println("progb:", liba.Hi()) }

progB/go.mod

module example.com/mywork/progb

go 1.13

The go build in libA directory is workable. But the go build failed in progB and shows

build example.com/mywork/progb: cannot load example.com/mywork/liba: cannot find module providing package example.com/mywork/liba

How to correct it?

Daniel YC Lin
  • 15,050
  • 18
  • 63
  • 96
  • 2
    https://github.com/golang/go/wiki/Modules#can-i-work-entirely-outside-of-vcs-on-my-local-filesystem – Charlie Tumahai Feb 22 '20 at 01:15
  • 1
    Possible duplicate of [How to use a module that is outside of “GOPATH” in another module?](https://stackoverflow.com/questions/52328952/how-to-use-a-module-that-is-outside-of-gopath-in-another-module) – Charlie Tumahai Feb 22 '20 at 01:39
  • I agree it is similar question, but I can not searched the answer from error message – Daniel YC Lin Feb 22 '20 at 02:27

1 Answers1

1

progB/go.mod should add require and replace statements in https://github.com/golang/go/wiki/Modules#can-i-work-entirely-outside-of-vcs-on-my-local-filesystem

module example.com/mywork/progb

require example.com/mywork/liba v0.0.0

replace example.com/mywork/liba => ../libA

go 1.13
Daniel YC Lin
  • 15,050
  • 18
  • 63
  • 96