I'm trying to get Go modules working without involving a remote repository.
src
is a local directory that contains all my projects, also projects that are written in other languages than Go. For simplicity I have only show the two directories relevant for my question:
src
├── client
│ ├── go.mod
│ └── main.go
└── lib
├── go.mod
└── lib.go
The go.mod
files are created by running the command go mod init client
in src/client
and go mod init lib
in src/lib
.
src/client/main.go:
package main
import "lib"
func main() {
lib.Hello()
}
src/lib/lib.go:
package lib
import "fmt"
func Hello() {
fmt.Println("Hello World")
}
What I'm trying to do is using the library lib.go in my main.go, but no matter what I put in the import path, this error is shown:
main.go:3:8: package lib is not in GOROOT (/usr/lib/go/src/lib)
Go version is go1.14.3
How do I correctly import Go code from local folders?