2条回答 默认 最新
- dsdzvprlp51692469 2017-03-31 19:28已采纳
No, in Go you import packages, not files. However, the compiler generally only includes in the compiled binary functions and types actually referenced, so even if you include a massive package in your import (which is discouraged anyway), they'll not usually be included in the final binary unless needed.
And as RayfenWindspear pointed out, if a package is large enough that you want to only import a file or two, that's probably a pretty good smell test that you need to refactor that package.赞 踩 打赏 评论分享
- doutu9810 2017-04-01 04:34
I realize this question is largely already answered. But here are my thoughts anyways.
If the specific files can work independently from the rest of the package or do so with some minor modifications you can just simply copy those files to the project you want to use them in. Then reference the functions/methods/etc directly. But if you are using parts of a big package in various projects it would definitely be more suitable to break it into smaller packages. Then you can use those parts independently in as many projects as you wish without the excess baggage.赞 踩 打赏 评论分享