Best-Practices

Go Project Structure: Patterns That Scale

Practical guide to structuring Go projects from flat layouts to hexagonal architecture, with examples for CLIs, APIs, and monorepos

Go doesn’t enforce a project layout. That freedom is powerful but requires discipline — start simple and let structure emerge as complexity grows.

Golang golang project-structure best-practices

Go: Handling time.Now() in Tests

Forget time-mocking libraries — a single function field on your struct is all you need to make time deterministic in Go tests

Time-dependent code is one of the classic pain points in unit testing. A function that calls time.Now() produces a different value every run, and assertions become a moving target. There are popular packages to solve this — but you don’t actually need any of them. A few lines of plain Go are enough.

Golang golang testing time