Home > Development > Go import

Go import

Go is a wonderful language, able to build complex applications with very minimal configuration information. For many apps, only import statements are required.

However, there are a couple of special import cases worth knowing about:

import . “github.com/user/repo”

From golang.org: “If a program imports a standard package using import . “path”, additional names defined in the imported package in future releases may conflict with other names defined in the program. We do not recommend the use of import . outside of tests, and using it may cause a program to fail to compile in future releases.”

import _ “github.com/user/repo”

From Andrew Gerrand (Google): “Prefixing an import
with an underscore causes the package to be imported for its
side-effects only. (that is, it’s init functions are executed and
global variables initialized)”

Categories: Development Tags: ,
  1. No comments yet.
  1. No trackbacks yet.