This question already has an answer here:
Is there a way to import a package on demand? Use case is the import of a profiling module, which I only want to import, when a certain command line flag has been set.
</div>
This question already has an answer here:
Is there a way to import a package on demand? Use case is the import of a profiling module, which I only want to import, when a certain command line flag has been set.
</div>
no. Golang is a static typed language. Everything has to be defined at compile time.
You can activate / deactivate the profiling with a flag though.
or use a build trick
// +build profile
package "mypackage"
import (
_ "profiling"
)
and then build with
go build -tags=profile