How I Structure New Projects In Golang
Summary
TLDRThe video discusses setting up a scalable project structure for a Go web application using Echo as the framework. It advocates for a pragmatic approach focused on simplicity, avoiding over-engineering. The proposed structure includes folders for binaries, commands, database logic, handlers, business logic packages, shared types, and utilities. It demonstrates this structure in an app called Leue - a marketplace to sell recurring revenue for upfront cash. The video argues developers should be full stack and balance tradeoffs themselves rather than follow dogmatic paradigms.
Takeaways
- 💻 The video discusses transitioning a company's project, named Laue, from Next.js and TypeScript to Go and Svelte Kit due to a significant increase in funding and project scope.
- 🔨 The presenter emphasizes there's no perfect project structure in programming; instead, it's about choosing what works best for the team and being willing to adapt.
- 💡 Encourages a result-driven development mindset over stressing about tools, packages, and organization methods.
- 🛠️ Explains the Go project structure, including the use of a 'bin' folder for binaries, a 'cmd' folder for main package entry points, and other organizational strategies.
- 📰 Highlights the flexibility of Go frameworks for the backend, stating that the choice of framework (Echo, Gin, etc.) doesn't significantly impact the end result.
- 💥 Discusses performance concerns, suggesting that for most projects, performance won't be a limiting factor until a very large user base is reached.
- 📖 Offers insights into database interaction, the use of global variables for ease of use, and the pros and cons of different approaches to handling database queries.
- 🏆 Shares a pragmatic approach to coding, advocating for simplicity and focusing on getting results rather than adhering strictly to certain programming paradigms.
- 📈 Talks about the importance of integrating business logic and data handling correctly within the project's structure to ensure scalability and maintainability.
- 📚 Advises on the significance of having a balanced view on technologies and methodologies, emphasizing that what works well for one team or project may not for another.
Q & A
What is Leue and what was the original technology stack used to build it?
-Leue is a company that the speaker created 3 years ago. The original project was built using Next.js for the front-end and TypeScript for the back-end.
Why did the speaker decide to rewrite Leue and change the technology stack?
-The scope of the project changed dramatically after the company received a large amount of funding. The speaker wanted to scale up the project, so they decided to rewrite the back-end in Go and use SpellKit for the front-end.
What is the speaker's view on choosing frameworks and architectural patterns?
-The speaker believes there is no one "perfect" choice. Developers should use what feels right for their needs instead of forcing specific paradigms. Performance differences rarely matter until an application reaches very large scale.
How does the speaker structure Go projects and why?
-The speaker uses a simple and modular structure with folders for handlers, packages, data, types, etc. This makes it easy to understand and scale up the project over time as needed.
Why does the speaker use a global database connection variable?
-For ease of use across different packages. The speaker argues this is okay if used carefully and may not matter much for testing since database access should be integration tested.
What is the purpose of the CMD folder and how does it work?
-The CMD folder contains main.go files that bootstrap different entry points into the application, like API servers. The binaries are then built into the bin folder for execution.
Where is business logic implemented in this structure?
-Most business logic is contained in the packages folder, separate from the database access in the data folder and HTTP handler functions.
How are endpoints and handlers organized?
-Handlers are organized by HTTP method into handler functions. Endpoints are grouped by concepts like buy/sell side using middleware.
How does the front-end connect to the Go back-end?
-The front-end uses SpellKit and calls API endpoints exposed from the Echo server in the main CMD API bootstrap.
What is the speaker's view on specialization between front-end and back-end development?
-The speaker argues developers should have full stack capabilities instead of identifying as a front-end or back-end specialist, since it's all just writing code.
Outlines
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowMindmap
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowKeywords
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowHighlights
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowTranscripts
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowBrowse More Related Video
Belajar Laravel 11 | 3. Struktur Folder
Node.js + Express - Tutorial - What is Express? And why should we use it?
Leave HTML - You can code frontend with Python now
Praktikum PBO - MVC pada proyek winform .NET C#
03. Folder Structure - Laravel 11 tutorial for beginners
Nestjs backend rest api - Ecommerce project. Introduction & setup.
5.0 / 5 (0 votes)