Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Go Module 9

Packages, modules and dependencies interview questions

Interview questions on packages, modules and dependencies: warm-ups, then what each harder question tests and how a good answer starts.

3 questions: 1 warm-up and 2 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    What makes a name in a Go package exported?

    Answered in the lesson Packages, exported names and initialisation

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    Your module has a package named helpers, meant only for its own commands. Another team now imports it and complains whenever you change it. What would you have done differently, and how do you fix it now without breaking them overnight?

    What it tests
    Knowing that exported names in an importable package are public API, the internal/ rule and whom it admits, and a migration that gives the other team a supported path.
    First step
    Separate two questions: what the other team needs, and what you never meant to support. Every exported name of a package that other modules can import is public, so the package should have lived under internal/ from the start, where the go command refuses imports from outside the tree.
    Follow-ups

    From the lesson Packages, exported names and initialisation

    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.

    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 3 minutes
  2. Fresher to mid

    A package opens its database connection in an init function and panics when the database is down. Since then, the unit tests of unrelated packages fail on every laptop without a database. Explain why, and how you would restructure the package.

    What it tests
    Knowing when init runs and for which programs, that it cannot return an error, and replacing hidden setup with an explicit constructor that returns one.
    First step
    Follow the imports. An init function runs in every program and test binary that imports its package, directly or through other packages, before any test starts, and it can report a failure only by panicking. So every test binary that reaches this package needs a database, whether its tests query one or not.
    Follow-ups

    From the lesson Packages, exported names and initialisation

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Go interview questions · The Go track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.