Skip to content

This is a template for initializing Go apps with the hexagonal structure according to best community practices

License

Notifications You must be signed in to change notification settings

goodylili/MyGoWebAppTemplate

Repository files navigation

MyGoWebAppTemplate

made-with-Go GoReportCard Go.mod version LICENSE

🗞️ Introduction

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.

⚠️ Understanding the Structure

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.

  1. cmd: This directory contains the main entry point for your server application.

    • server: Subdirectory for the server application.
      • main.go: The main Go source code file for your server application.
  2. config: This directory stores configuration files for your application.

  3. docs: Documentation related to your project.

  4. 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.
  5. 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.
  6. 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.

🏁 Getting Started

You can use the gonew command or the bash creator.sh script to initialize this project.

🤩 Using Gonew

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 Bash Script

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.

🛠️ Technologies and Tools

Go - The programming language used

GitHub Actions - GitHub CI/CD tool

Make - Build automation tool

👏 Contributing

Contributions are welcome! Feel free to open a pull request right away.

📃 License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

This is a template for initializing Go apps with the hexagonal structure according to best community practices

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published