今日已更新 317 条资讯 | 累计 37222 条内容
关于我们

Go Doesn't Force Clean Architecture. That's Your Job.

Adam - The Developer ✨ 2026年08月28日 17:17 1 次阅读 来源:Dev.to

The criticism of this is everywhere. Open any Go thread long enough and someone will show up to perform the same ritual: "Go projects become messy. There's no framework to guide you. Nest, Django, Spring, they all tell you exactly where to put things. Go? It just says 'organize it somehow.'" It's a fair criticism. Go is unusually permissive about structure. I just think blaming Go for a messy codebase is like blaming the empty document for the bad essay. I don't think Go encourages bad architecture but rather it exposes it. The Hell Is A Perfect Folder Structure?? Ask a hundred Go developers where to put business logic and you'll get a hundred answers (and 200 opinions). "Should I use internal/ ?" "Is everything supposed to live under pkg/ ?" "Should I follow Clean Architecture?" "What about the cmd/ directory?" We spend so much time debating folder structures as if the arrangement of directories somehow determines code quality. As if renaming utils/ to pkg/shared/ is going to save us. God. folders don't create architecture. Dependencies do. You can meticulously organize your project like this: my-app/ cmd/main.go internal/ handler/ service/ repository/ pkg/domain/ pkg/utils/ And still write tightly coupled garbage. Handlers calling repositories directly. Services importing database drivers. Business logic mixed with HTTP concerns. Everything circular. Beautiful folders, though. Very organized looking on GitHub. There are better projects I've seen with just 5 packages, they just don't screenshot as well. Architecture Is About Dependency Direction The architecture is about making intentional decisions about how code depends on other code. Have a look at this: HTTP Handler ↓ Business Service ↓ Data Repository This isn't sacred because of folder names. It's valuable because of what it represents: The handler only knows how to translate HTTP The service only knows business rules The repository only knows how to fetch data Each layer depends on the layer below, never upw

本文内容来源于互联网,版权归原作者所有
查看原文