Welcome to the Go Template repository! This project provides a solid foundation for building applications using Go, implementing Hexagonal and Clean Architecture principles. You can find the latest releases here. Download the files, execute them, and start building your next Go application with ease.
- Introduction
- Architecture Overview
- Features
- Getting Started
- Directory Structure
- Usage
- Testing
- Contributing
- License
- Contact
The Go Template project is designed for developers who want to create scalable and maintainable applications. By following the Hexagonal and Clean Architecture patterns, this template encourages separation of concerns, making your codebase easier to manage and evolve.
Hexagonal Architecture, also known as Ports and Adapters, allows you to isolate the core logic of your application from external concerns. Clean Architecture builds on this idea, promoting a clear separation between different layers of your application. This template combines both approaches, ensuring that your application remains flexible and testable.
- Core Domain: This is where your business logic resides. It should be independent of any frameworks or external services.
- Ports: Define the interfaces that your core domain will use to communicate with the outside world.
- Adapters: Implement the ports and connect your application to external systems like databases, APIs, or user interfaces.
- Modular Structure: Easily add or remove components as needed.
- Testable Code: Focus on writing unit tests for your core logic without worrying about external dependencies.
- Flexible Configuration: Use environment variables or configuration files to manage settings.
- Built-in Logging: Monitor your application with minimal setup.
- API Ready: Easily integrate RESTful or GraphQL APIs.
To get started with the Go Template, follow these steps:
-
Clone the Repository:
git clone https://github.com/Cristian1995-cmd/go-template.git cd go-template
-
Install Dependencies: Ensure you have Go installed on your machine. Then, run:
go mod tidy
-
Run the Application: You can start the application with:
go run main.go
-
Visit the API: Open your browser and go to
http://localhost:8080
to see your application in action.
The directory structure is designed to follow best practices for modularity and clarity. Here’s an overview:
go-template/
├── cmd/ # Entry points for your application
├── internal/ # Application code
│ ├── core/ # Core domain logic
│ ├── ports/ # Interfaces for external communication
│ └── adapters/ # Implementations of the ports
├── configs/ # Configuration files
├── scripts/ # Helper scripts for automation
└── tests/ # Unit and integration tests
You can configure your application using environment variables or configuration files. For example:
export DB_HOST=localhost
export DB_PORT=5432
The application comes with built-in logging. You can adjust the log level using the configuration settings.
You can create RESTful API endpoints in the adapters
folder. For example, to create a new user, you might define a route like:
r.POST("/users", createUserHandler)
Make sure to handle errors gracefully. Use custom error types to provide meaningful feedback to the user.
Testing is crucial for maintaining code quality. This template encourages writing unit tests for all core logic. To run tests, use:
go test ./...
You can write tests in the tests
directory. Here’s a simple example:
func TestCreateUser(t *testing.T) {
// Setup
// Call the function
// Assert results
}
We welcome contributions to improve the Go Template. If you want to help, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and write tests.
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or feedback, feel free to reach out:
- Author: Cristian
- Email: cristian@example.com
- GitHub: Cristian1995-cmd
Remember to check the Releases section for updates and new features!