Conditional import

Hello there,
Is there any way to import a golang package conditionally?
Life if I am in dev environment I want to import pprof but if I am in production environment I don’t want to import it.

Is there any way to do that?

How does your code use this package? If if uses any exported type of function from it, you always have to import it.

I tried so far, and found build tags as a solution for this.

I didn’t use any exported function, you know pprof package can work without any direct usage .

Good to read. Maybe you could answer your own question and share what you’ve found with the other readers of this forum. If you then mark your answer as the one that solved the problem, everybody benefits.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.