import the os package with a blank identifier in go

In Go, to import the "os" package with a blank identifier, you can use the following code snippet:

main.go
import _ "os"
14 chars
2 lines

The blank identifier is represented by an underscore character. This tells the Go compiler to import the package, but not to assign it to a variable. This is useful if you just need to execute a package's initialization functions, but you don't need to use any of its exported symbols directly in your code.

related categories

gistlibby LogSnag