import the fmt package with a blank identifier in go

To import the fmt package with a blank identifier in Go, use the following code:

main.go
import _ "fmt"
15 chars
2 lines

The underscore character _ is used to assign the imported package to the blank identifier, which discards the visibility of that package in the code.

This is generally used when you need to import a package just for its side effects, like running its init() function, without actually using any of its features or functions in the code.

related categories

gistlibby LogSnag