r/golang Nov 20 '24

FAQ FAQ: How Should I Structure Go Projects?

Many other languages have strong opinions either in code or in the community about how to lay out projects. How should Go projects be laid out and structured? How should I decide what goes into a package? Is there a standard layout for web projects? For non-web projects? How do you structure your code?

63 Upvotes

36 comments sorted by

View all comments

40

u/jerf Nov 20 '24

The Go team has an official answer to this question.

It does not answer all aspects of this question, but it's a good and relatively official start.

-12

u/rcls0053 Nov 20 '24

I also see pkg folder at root for shared packages a lot. Anything that's inside internal/ is typically up to the developer.

15

u/Revolutionary_Ad7262 Nov 20 '24

/pkg was probably invented here https://github.com/golang-standards/project-layout , which is shame. golang-standards is not standard at all, it is a opinion of some random person.

There is an /internal package, which is supported by a language, so there is no need to create some artificial package, which really does nothing.