Local modules not found


(F) #1

Hello,

I have difficulties to migrate my code to use modules:

I have 2 modules, in my GOPATH:

src/project/lib and src/project/app

src/project/lib/main.go

package lib

import (
"fmt"
)

func Try() {
    fmt.Println("test")
}

src/project/app/main.go

package main

import (
	"project/lib"
)

func main() {
	lib.Try()
}

When GO111MODULE=offit build with no problem.
But when switching to GO111MODULE=onit can find the lib anymore

> go build
build app: cannot load project/lib: cannot find module providing package project/lib

Thanks for your help


(Ashish Shekar) #2

Hello,

The GO111MODULE=on option will look at the following path NAME/lib.

In this case, whatever you have initialized the module with the command go mod init NAME will be your starting path. and not project.

you can check the go.mod file, inside that you’ll find the module NAME line. The NAME will be your entry package.

Hope this helps.


(F) #3

Thanks that makes sense.

I believe I need to use the redirect feature to map to the correct path.