Go Module 1
Getting started with Go 1.27 interview questions
Interview questions on getting started with Go 1.27: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
What does the Go 1 compatibility promise guarantee, and what does it leave out?
-
Fresher
What is GOPATH used for in a project that uses modules?
Answered in the lesson Install Go 1.27 and set up your editor
-
Fresher
What is the difference between go run and go build?
Answered in the lesson Your first Go program: go run and go build
-
Fresher
How do you find which go test flag runs only some of the tests, without leaving the terminal?
Answered in the lesson Find answers: go help, go doc and pkg.go.dev
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Fresher to mid
Your team runs a Python API that serves 2,000 requests a second, and it must also ship a command-line tool to 300 laptops on three operating systems. A colleague proposes writing both in Go. How do you decide for each project, and what would you measure before deciding?
- What it tests
- Choosing a language from a project's constraints instead of taste: how it ships, how it handles concurrent work, which libraries it needs and what a rewrite costs, backed by measurements.
- First step
- Treat them as two decisions, because their constraints differ. For the tool, list what the laptops have installed: if no runtime is guaranteed, one executable per system is a strong argument. For the API, measure where its time and money go today before assuming a rewrite would make it faster.
- Follow-ups
-
- What would make you keep the API in Python?
- How would you show that a Go rewrite pays off before rewriting all of it?
- What does shipping one Go tool to three operating systems involve?
From the lesson What Go is and where it fits
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
You raise the go line in go.mod from go 1.21 to go 1.22 so that you can range over integers. One test now fails, and nobody changed any code. How can that happen, how do you find the cause, and how would you raise the go line safely next time?
- What it tests
- Knowing that the go line sets the language version and GODEBUG defaults, the Go 1.22 loop-variable change, and a safe routine for raising the line.
- First step
- Start from what the go line does: it sets the language version the compiler applies to the module's code. Then list the changes of meaning between 1.21 and 1.22. Per-iteration loop variables are the change that can alter a test's result without any code change.
- Follow-ups
-
- Which loops can change behaviour, and which cannot?
- How do you find the one loop that broke the test?
- What else changes when the go line moves, besides the language?
From the lesson What Go is and where it fits
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
After a Go upgrade, every build on a teammate's laptop fails with "compile: version "go1.26.8" does not match go tool version "go1.27.1"". What causes it, how do you confirm the cause, and how would you keep build machines from ever meeting it?
- What it tests
- Knowing how the go command finds its toolchain and its settings, reading a version-mismatch error precisely, and making build machines reproducible.
- First step
- Read the error literally: the go command is version 1.27.1, but the compiler it ran belongs to 1.26.8. So something points the new go command at the old installation's folder, and that is almost always a GOROOT set by hand: in a shell profile, or saved in the go env file by an older Go's go env -w.
- Follow-ups
-
- How do you find where GOROOT is being set?
- Why does go version still print go1.27.1 on that laptop?
- How should a build machine pin its Go version?
From the lesson Install Go 1.27 and set up your editor
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
Your company network blocks proxy.golang.org, and a new hire's go build cannot download any module. Which settings decide where modules come from and how they are checked, what would you change, and what does each choice risk?
- What it tests
- Knowing GOPROXY with its separators and keywords, GOSUMDB and GOPRIVATE, and the security cost of each way around a blocked proxy.
- First step
- Print the settings first: go env GOPROXY GOSUMDB GOPRIVATE. The default asks proxy.golang.org and falls back to direct downloads only when the proxy answers 404 or 410, so a blocked connection is a terminal error, and every download is still checked against sum.golang.org.
- Follow-ups
-
- What changes with GOPROXY=direct, and with a pipe instead of the comma?
- When are GOPRIVATE and GONOSUMDB the right tools?
- Why is GOSUMDB=off a poor fix?
- How would you set this up once for a whole team?
From the lesson Install Go 1.27 and set up your editor
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Go refuses to compile a function with an unused local variable, or a file with an unused import, yet it accepts an unused function or an unused package-level variable. Why the difference, and how do you work with the rule while you debug?
- What it tests
- Knowing what the specification and the gc compiler require, why the rules exist, and the honest workarounds as opposed to the ones to keep out of committed code.
- First step
- Separate the two rules. The specification itself makes an unused import illegal, while an unused local variable is an implementation restriction that the specification allows and gc applies. Then ask what each check protects: imports cost build time, and an unused local is very often a bug.
- Follow-ups
-
- Why are unused package-level variables and functions allowed?
- What does _ = x do, and when is it acceptable?
- How do editors keep the imports right for you?
From the lesson Your first Go program: go run and go build
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A binary built on a developer's Mac runs fine there, but the same file copied to a Linux server fails with "exec format error". Explain why, how you would build it correctly, and how you would check any binary before it ships.
- What it tests
- Understanding GOOS and GOARCH, cross-compiling with go build, what cgo changes, and reading what a binary was built for.
- First step
- The message comes from the Linux kernel: the file is not a format it can load. go build on the Mac made a Mach-O file for darwin/arm64. Build for the server instead, with GOOS=linux and GOARCH set to its processor, amd64 or arm64.
- Follow-ups
-
- How do you find the server's processor architecture?
- When does CGO_ENABLED matter for a build like this?
- How would checking the binary before shipping have caught the mistake?
From the lesson Your first Go program: go run and go build
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
You need a standard-library function that splits a "key=value=more" string at its last "=" sign. Without a search engine, how do you find the function, check how it behaves at the edges, and confirm that behaviour before you rely on it?
- What it tests
- Using go doc to search a package offline, reading a doc comment precisely, and confirming behaviour with a small program or an executable example.
- First step
- Start from the package, not the function. go doc strings lists every function with its signature, so scanning it for Cut and LastIndex is quick. Then read the chosen function's own documentation, go doc strings.CutLast, which says what it returns when the separator is missing.
- Follow-ups
-
- What changes if your module's go line is go 1.26?
- How do you turn your check into a test that also documents the function?
- When is the source, go doc -src, worth reading?
From the lesson Find answers: go help, go doc and pkg.go.dev
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Two modules on pkg.go.dev solve your problem. One is at v0.9.3 with thousands of importers, the other at v2.1.0 with a few hundred. How do you choose, and what do the version number, the licence and the importer count tell you, and not tell you?
- What it tests
- Reading module versions as promises, checking licences and known vulnerabilities, and not mistaking popularity for quality or safety.
- First step
- Read the version numbers as promises. A v0 version makes no compatibility promise at all, while v2.1.0 says its v2 API stays compatible until a v3, which would get a new module path. Check the licence before anything else, since it decides whether you may use the code at all.
- Follow-ups
-
- What does a missing Redistributable license mark mean for you?
- How would you check the two modules for known vulnerabilities?
- When would you write the code yourself instead?
From the lesson Find answers: go help, go doc and pkg.go.dev
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes