Skip to content
Learn Netverks

Lesson

Step 11/36 31% through track

packages-imports

Packages and imports

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Packages and imports: the syntax, patterns, and safety habits you need before advancing in Go.

Teams still ship Packages and imports in Go codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Packages and imports in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

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

  1. Q: How does Go export symbols?
    A: Uppercase first letter exports from the package; lowercase stays internal.
  2. Q: init function?
    A: Package-level func init() runs before main—use for registration or setup, not heavy logic.

Self-check

  1. What happens with an unused import?
  2. 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.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Exported name rule?
  • init() when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump