Golang Packages & Modules Quiz
35 comprehensive questions on Golang packages and modules, covering package creation, exported vs unexported identifiers, Go modules usage, dependency management, and versioning rules — with 18 code examples demonstrating package organization and module management.
Question 1
What is a package in Golang?
Question 2
How do you declare a package?
package main
import "fmt"
func main() {
fmt.Println("Hello")
}Question 3
What is the difference between exported and unexported identifiers?
Question 4
What happens when you try to access an unexported identifier from another package?
package main
import "mypackage"
func main() {
mypackage.unexportedFunc() // Error
}Question 5
What is a Go module?
Question 6
How do you initialize a Go module?
go mod init example.com/myprojectQuestion 7
What is the go.mod file?
module example.com/myproject
go 1.21
require (
github.com/some/lib v1.0.0
)Question 8
How do you add a dependency to a module?
go get github.com/some/[email protected]Question 9
What does go mod tidy do?
Question 10
What is semantic versioning in Go modules?
Question 11
In a team project, you're creating a shared utility package. How should you name exported functions?
Question 12
What is the difference between internal and regular packages?
project/
├── internal/
│ └── utils/
│ └── helper.go
└── pkg/
└── api/
└── client.goQuestion 13
How do you import a package?
package main
import (
"fmt"
"github.com/user/mylib"
)
func main() {
fmt.Println(mylib.SomeFunc())
}Question 14
What is vendoring in Go?
Question 15
How do you update a dependency to latest version?
go get github.com/some/package@latestQuestion 16
What is the go.sum file?
Question 17
In a library you're publishing, how should you version releases?
Question 18
What is a replace directive in go.mod?
module example.com/myproject
go 1.21
require github.com/some/lib v1.0.0
replace github.com/some/lib => ./local/forkQuestion 19
How do you create a package with multiple files?
mypackage/
├── utils.go
├── types.go
└── constants.goQuestion 20
In a microservices architecture, you're creating shared packages. Should you use internal/ or pkg/ for shared utilities?
Question 21
What is the GOPROXY environment variable?
Question 22
How do you handle incompatible dependency versions?
go mod edit -require=github.com/[email protected]Question 23
What is the difference between go.mod and go.sum?
Question 24
How do you publish a Go module?
git tag v1.0.0
git push origin v1.0.0Question 25
What is a major version change in semantic versioning?
Question 26
How do you organize a large Go project?
project/
├── cmd/
│ └── server/
├── internal/
│ └── database/
├── pkg/
│ └── api/
└── go.modQuestion 27
What happens when you import an unused package?
package main
import (
"fmt"
"unused/package" // Not used
)
func main() {
fmt.Println("Hello")
}Question 28
How do you import for side effects only?
import _ "github.com/lib/drivers"Question 29
What is the GOSUMDB environment variable?
Question 30
In a CI/CD pipeline, how should you cache Go dependencies?
Question 31
What is the difference between require and replace in go.mod?
require github.com/lib v1.0.0
replace github.com/lib => ./forkQuestion 32
How do you work with private modules?
go env -w GOPRIVATE=example.com/private/*Question 33
What is minimal module compatibility?
Question 34
How do you debug module issues?
go mod why github.com/some/package
go list -m allQuestion 35
What is the most important principle for Go package design?
