Skip to content
Preptima
mediumDesignCodingMidSeniorStaff

Go gives you no project layout and no dependency-injection container. How do you structure a service so it stays testable as it grows?

5 min readUpdated 2026-08-15

Answer

Short answer

Wire dependencies explicitly through constructors from one place in main, define narrow interfaces where they are consumed rather than implemented, and keep handlers thin enough that the logic beneath is testable without a server.

Was this answer helpful?

Likely follow-ups

  • Where does the interface for your database live, and why there?
  • How do you test a handler without starting a server?
  • When is a global logger acceptable and when is it not?
  • What breaks first when the package tree gets deep?

Related questions

Further reading