更新时间:2023-02-25 21:07:46
首先,请务必阅读并理解如何编写Go代码" 文档.
First, be sure to read and understand the "How to write Go code" document.
实际答案取决于您的自定义程序包"的性质.
The actual answer depends on the nature of your "custom package".
如果打算用于一般用途,请考虑使用所谓的"Github代码布局" .基本上,您将库设为一个单独的go get
-table项目.
If it's intended to be of general use, consider employing the so-called "Github code layout". Basically, you make your library a separate go get
-table project.
如果您的库供内部使用,则可以这样:
If your library is for internal use, you could go like this:
演示:
src/
myproject/
mylib/
mylib.go
...
main.go
现在,在***main.go
中,您可以import "myproject/mylib"
,它将正常运行.
Now, in the top-level main.go
, you could import "myproject/mylib"
and it would work OK.