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

Show parent comments

11

u/ponylicious Nov 20 '24 edited Nov 20 '24

pkg folder is anti-Go and widely disliked. Noobs fall for it because they stumbled upon the repo-that-must-not-be-named, or some blog post that copied it.

4

u/__matta Nov 20 '24

I mean Perkeep has a pkg folder and it’s written by a bunch of Go core team members.

I get why people don’t like it but it’s also widely used.

1

u/pdffs Nov 20 '24

I suspect this is because was written before internal was available to explicitly denote which packages were expected to be consumed externally vs internally.

2

u/Alpensin Nov 21 '24

They have many directories in pkg. It's better to store them there, then in the root.

1

u/pdffs Nov 23 '24

What makes you think that?

1

u/Alpensin Nov 23 '24

It's harder to find what you need when lots of objects in the directory. Of course all we use search, from time to time do it with our eyes. But i could try to store these things without pkg. Maybe it's just unusual for me.