导入本地包的最佳方法是什么?
通常我通过
import "github.com/crsov/myproj/mypkg"
但是当我编辑它们时,我需要 go get -u "github.com/crsov/myproj/mypkg"
每次保存.
but when i am editing them i need to go get -u "github.com/crsov/myproj/mypkg"
every save.
这是导入本地包的最佳方式吗?我找到了很多关于这个问题的答案,但其中大部分都是针对旧版 golang 的.
That's the best way to import local package? I have found many answers to this question but most of them are for older golang versions.
如果你有一个很新的本地包还没有稳定下来,你可以这样做相反:
If you have a local package that is very new and has not stabilized, you can do this instead:
go mod init mypkg
并像这样导入:
import "mypkg"
那么你不必担心从互联网上拉,它只会拉从本地目录.然后一旦你的包稳定了,你就可以重命名以供其他人使用.
then you dont have to worry about pulling from the internet, it will just pull from the local directory. Then once your package stabilizes, you can rename so that it can be properly published for others to use.