Learn Concurrency in Go by Building a Download Manager Part-2

Learn Concurrency in Go by Building a Download Manager Part-2

Go Project Folder Structure And Package Explain

In the First Article, we set up goenv and installed go in our local environment. Now we will create a proper folder structure for the golang cli application and under what's go modules.

Overview

Having a clean code and a proper directory structure can have a significant impact on the overall quality of a project. It not only makes the code easier to navigate, but it also allows for easier collaboration and maintenance. When a project has a clear and consistent structure, it is easier for new team members to jump in and understand the codebase quickly.

Furthermore, it can also help with code reuse and modularity. By breaking down the project into smaller, modular components, it becomes easier to identify and reuse code in other parts of the project or other projects altogether. This can save a lot of time and effort in the long run, especially when working on larger and more complex projects.

Another advantage of having a well-organized codebase is that it can help with debugging and troubleshooting. When an issue arises, it can be easier to locate and fix the problem if the code is structured in a logical and organized manner. This can help to minimize downtime and ensure that the project stays on track.

Overall, following clean code and proper directory structure is essential for any software development project. It can lead to increased productivity, better collaboration, easier maintenance, and ultimately, a higher-quality end product.

Cookiecutter

So order to have clean code and also get started quickly, my recommendation is to use the cookiecutter Python package, easily installable with pip or other package managers, you can get started with proper folder structure in no time.

pip install cookiecutter
// or
pipx install cookiecutter

pipx is a package manager for Python applications that allows you to install and manage them in isolated environments. Unlike pip, pipx installs packages into separate virtual environments, preventing conflicts with other Python packages installed on your system. This makes it easier to manage dependencies and ensures that applications have their own isolated environment to run in.

Now, use cookiecutter to download and configure the go template

cookiecutter https://github.com/notsatan/go-template/

After a few quick questions, you can get started with the coding.

You will have a similar structure as below,

 .
├──  bin # contains binary files that have been built
├──  build-script.sh # used to build the project
├──  CONTRIBUTING.md #  guidelines for contributing to the project
├──  cookiecutter-config-file.yml
├──  coverage
├──  docker # contains Dockerfiles
├──  go.mod # Go's module system to manage dependencies
├──  LICENSE
├──  main.go # contains the main code for the project
├──  main_test.go # contains test cases for the code in main.go
├──  Makefile # contains make targets for building and testing 
├──  README.md # contains information about the project 
└──  src # contains the source code for the project

What is a go package?

Overall, packages are a key feature of Go that enable developers to build modular, reusable, and maintainable programs. Read this go doc to learn in detail.

Conclusion

So far we have set up the code base for our project and understand the importance of the go package. In the next part, we will dive into cli aspect.

All the code is available here, https://github.com/coderj001/goget/tree/part-02