I have faced several times when go mark my import and says it is local import
If you mean relative imports like ../foo
these are not recommended. Instead use a full import path like github.com/example/foo
.
(If you mean something else, please clarify what your code is and what error you get.)
I mean relative imports, thanks! Why they are not recomended?
For one reason, because it doesnât say what the import is. If you see a import "../foo"
that doesnât mean anything to you unless you have the same stuff on disk as I have. Giving you just a file is impossible as it removes the context. Tooling doesnât understand it. It doesnât work well with modules. And so on.
It is possible to work entirely outside of VCS on my local filesystem.
See,https://github.com/golang/go/wiki/Modules#can-i-work-entirely-outside-of-vcs-on-my-local-filesystem?
For me, i prefer to use shorter package name, instead something like âsome_vcs.url/my_name/my_packageâ.
Here is my directories:
./
./common
./common/go.mod (module local/common)
./service
./service/go.mod
>module local/service
>require local/common v0.0.0
>replace local/common => ../common <HERE
./service/main.go
>package main
>import "local/common"
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.