Hi. Error text : could not import entities (cannot find package “entities” in any of /usr/lib/go-1.20/src/entities (from $GOROOT) /home/jk/go/src/entities (from $GOPATH))
I’ve simple structure
entities|entity.go
main.go
entities is a package. It tries to find along this way
/home/jk/go/src/entities (from $GOPATH))
Go has no relative import paths—at least, not directly.
What is the module name that you gave your module? (It’s stored in go.mod, in the line that starts with module.)
Add the module name as a prefix to the import path:
import "<your module name>/entities".
This should make the import work.
(See also the Multiple Files example in the Go Playground. (The “files” are just sections in the editor widget, separated by -- filename.ext -- lines.) The module name is play.ground, the package foo lives in subdirectory foo/, and the resulting import path is play.ground/foo.)
No, it does not get shorter than that. The module-based import path helps avoid ambiguities. Imagine you create a package named os and import it as os. The compiler would not be able to distinguish your os package from the os package in the standard library.