This is a template for initializing Go apps with the hexagonal structure according to the best practices as overviewed through the community.
You're going to find this useful if you're building an app that you intend to use and support over a long period of time.
First, you're going to tweak this structure for your app's use case. This template simply eliminates the overhead of manually initializing a project.
-
cmd: This directory contains the main entry point for your server application.
-
config: This directory stores configuration files for your application.
- config.yaml: Configuration settings and parameters.
-
docs: Documentation related to your project.
- Getting Started.md: Instructions on how to get started with your application.
-
internal: Contains internal application code not meant to be exposed as a public API.
- handlers: Subdirectory for request handlers.
- handlers.go: Code for defining and implementing request handlers.
- utils: Subdirectory for utility functions.
- utils.go: Utility functions used within the application.
- handlers: Subdirectory for request handlers.
-
scripts: Contains scripts for automating various tasks.
- PushaG.sh: A script for a task named "PushaG."
- creator.sh: A script that might be related to creating something for your application.
-
static: Contains static assets like images.
- img.jpg: An image file used in your application.
Each of these subdirectories serves a specific purpose in organizing your application's code and resources. The structure helps keep your codebase modular and maintainable by separating concerns and functionalities into different directories.
You can use the gonew
command or the bash creator.sh script to initialize this project.
Using gonew
will ensure that you also get additional files and file content. Google gonew
and check the LogRocket
blog for a tutorial I wrote on how you can use gonew
to streamline your apps' development.
First, Install gonew
with this command line
go install golang.org/x/tools/cmd/gonew@latest
Next, run this command to complete the setup with gonew
and start building.
gonew -dir <directory-you-want> -v github.com/Goodnessuc/MyGoWebAppTemplate <your-project-name>
The command will create the exact structure of the project as is on GitHub.
Using the creator.sh bash script is a fast alternative to getting started.
The bash script also affords you more control over the contents of your app files in a minimalistic manner
Run this command in the terminal of your project's working directory to create the directory structure and files
mkdir -p cmd/server config internal/handlers internal/utils scripts static docs
touch .gitignore LICENSE Makefile README.md Dockerfile .env.example go.mod go.sum scripts/PushaG.sh
You've successfully set up your project's structure with the Bash Script.
Go - The programming language used
GitHub Actions - GitHub CI/CD tool
Make - Build automation tool
Contributions are welcome! Feel free to open a pull request right away.
This project is licensed under the MIT License - see the LICENSE.md file for details