I have set $GOPATH, and importing some part of my source code which is present in $GOPATH/src.
Package I need to import is written by me and stored in GOPATH/src I have named it as otelkafkago and it's path is GOPATH/src/otelkafkago
I have one more code base elsewhere on my HardDisk and when I try to compile that, it gives me
main.go:51:2: package otelkafkago is not in GOROOT (/usr/local/go/src/otelkafkago)
I have imported it as
import(
"otelkafkago"
)
Following is my screen capture during build,
kshitijpatil@PNQ-KPATIL checkoutservice % echo $GOPATH
/Users/kshitijpatil/go/
kshitijpatil@PNQ-KPATIL checkoutservice % go build
main.go:51:2: package otelkafkago is not in GOROOT (/usr/local/go/src/otelkafkago)
kshitijpatil@PNQ-KPATIL checkoutservice % env GOPATH=/Users/kshitijpatil/go go build
main.go:51:2: package otelkafkago is not in GOROOT (/usr/local/go/src/otelkafkago)
kshitijpatil@PNQ-KPATIL checkoutservice %
Since Go 1.16, the module-aware mode is enabled by default, regardless of whether a
go.mod
file is present in the current working directory or a parent directory.In your case, it would be easier to migrate to go modules, even though setting
GO111MODULE
toauto
might help.As commented, the first line of your
go.mod
should be:Your other "otelkafkago" project, it should have its own
go.mod
withmodule otelkafkago
as first line, and be built first.