Go organizes code into packages—one directory, one package (usually). Import paths use module paths like github.com/org/repo/pkg. The playground uses a single main package; locally you split code across files in the same package.
Import rules
import "fmt"
import (
"errors"
"strings"
)
Unused imports fail compilation. Dot imports (. "fmt") and blank imports (_ "image/png") exist for special cases—avoid dot imports in application code.
Visibility
Exported identifiers start with an uppercase letter within a package. Package name is typically the last element of the import path—short, lowercase, no underscores.
Important interview questions and answers
- Q: How does Go export symbols?
A: Uppercase first letter exports from the package; lowercase stays internal. - Q: init function?
A: Package-levelfunc init()runs before main—use for registration or setup, not heavy logic.
Self-check
- What happens with an unused import?
- How do you make a type visible to other packages?
Tip: Uppercase exports symbols across packages—fmt.Println is exported; unexported helpers stay lowercase within the package.
Interview prep
- Unused imports?
Compile error—remove or use the import; Go enforces clean imports.
- init function?
Runs before main for package setup—keep lightweight; avoid heavy side effects.