A boilerplate template for initializing a Golang API with essential features. This template includes structured project organization, basic configurations, logging, routing, and database integration to help you quickly set up and start building your Golang-based APIs.
- Structured Project Layout: Organized folder structure for scalability and maintainability.
- Configuration Management: Easy configuration with
viper
. - Logging: Integrated Zap logger for structured logging.
- Routing: HTTP routing with Chi.
- Database Integration: PostgreSQL integration using
sqlx
andgoqu
. - User CRUD: Basic user CRUD operations.
-
Clone the repository:
git clone https://github.com/jorgeAM/go-template.git cd go-template
-
Install dependencies:
go mod tidy
-
Set up environment variables: Create a .env file in the root directory with the following variables (you can copy .env.example):
PORT=8080 POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_DB=coderhouse POSTGRES_USER=admin POSTGRES_PASSWORD=passwd123 POSTGRES_MAX_IDLE_CONNECTIONS=10 POSTGRES_MAX_OPEN_CONNECTIONS=30
-
Run the application:: just run the following code:
make run
you can also run:
go run cmd/go-template/main.go | jq '.'
- Access the API at
http://localhost:8080
. - Basic user CRUD endpoints are available under
/users
.
This project is licensed under the MIT License - see the LICENSE file for details.