Golang / GoLang Production Patterns and Web Standards Interview Questions
What is the recommended project structure for a production Go service?
Go does not mandate a project layout, but the community has converged on a practical structure that separates concerns without over-engineering. The key principle: packages should be named for what they contain, not what they do.
myservice/
├── cmd/
│ └── server/
│ └── main.go # entry point — only wires dependencies
├── internal/ # private packages — not importable by other modules
│ ├── api/ # HTTP handlers and middleware
│ │ ├── handler_user.go
│ │ └── middleware.go
│ ├── domain/ # business logic — no infrastructure dependencies
│ │ ├── user.go # User type, UserService interface
│ │ └── user_service.go # UserService implementation
│ ├── store/ # data access layer
│ │ ├── postgres/
│ │ │ └── user_store.go # postgres implementation of UserRepository
│ │ └── memory/
│ │ └── user_store.go # in-memory implementation for tests
│ └── config/
│ └── config.go # configuration loading and validation
├── pkg/ # reusable packages (can be imported externally)
│ └── httputil/
│ └── response.go # writeJSON, writeError helpers
├── migrations/ # database migration SQL files
├── docker/ # Dockerfile, docker-compose.yml
├── go.mod
├── go.sum
├── Makefile # build, test, lint targets
└── README.md
// Key decisions:
// internal/ prevents external packages from importing your internal logic
// cmd/ can have multiple binaries (server, worker, cli)
// domain/ has NO imports from store/ or api/ — dependency flows inward
// Tests live alongside the code they test (*_test.go files)
// main.go is thin — create, connect, start; no business logic
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
