Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to import only a function from a package?

Tags:

import

go

Sometimes I need only a function from a package so importing the whole package doesn't seem performance wise. Thus the question: Is it possible to import only a function ?

like image 463
The user with no hat Avatar asked Apr 14 '14 09:04

The user with no hat


Video Answer


2 Answers

  1. No, this is not possible.

  2. No, this has no impact on performance. Unused stuff from a package should be dropped by the linker so it won't clutter your binary.

like image 168
Volker Avatar answered Sep 28 '22 06:09

Volker


Agree with @Volker that its not possible and that it would not clutter your binary. Some further considerations if you are still keep on only having the package are that the package could be Forked. Whereas if its a library from Go the source code is all available for view and you can get plenty of ideas about how you can implement you own equivalent function.

like image 30
miltonb Avatar answered Sep 28 '22 05:09

miltonb