导入本地包的最佳方法是什么? [英] What is the best way to import local package?

查看:79
本文介绍了导入本地包的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我通过

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.

https://golang.org/doc/code.html

这篇关于导入本地包的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆