A RESTful API server built with Go, Gin, and GORM that provides CRUD operations for managing tasks.
.
├── .env.example # Example environment variables
├── .env # Environment variables for development
├── .test.env # Environment variables for testing
├── .air.toml # Configuration for Air (live reloading) for Windows
├── .air.linux.toml # Configuration for Air (live reloading) for Linux
├── go.mod # Go module dependencies
├── go.sum # Go module checksum
├── Dockerfile # Docker configuration for building the application
├── docker-compose.yml # Docker Compose configuration for local development
├── api/ # API handlers and routes
│ └── task/ # Task-related API endpoints
├── cmd/ # Application entrypoints
│ └── main.go # Main application entry point
├── config/ # Application configuration
├── keys/ # Authorization keys and certificates
├── startup/ # Server initialization and module setup
├── utils/ # Utility functions and helpers
└── tmp/ # Temporary files (generated during development)
- Go - Programming language
- Gin - Web framework
- GORM - ORM library for database operations
- PostgreSQL - Database
- Docker - Containerization
- Air - Live reloading for development
- Go 1.24 or higher
- Docker and Docker Compose (for local development with database)
- Git
-
Clone the repository:
git clone <repository-url> cd crud-server
-
Set up environment variables:
cp .env.example .env
Edit the
.env
file as needed with your configuration.
-
Install dependencies:
go mod download
-
Run the application:
go run cmd/main.go
-
Install Air if you haven't already:
go install github.com/cosmtrek/air@latest
-
Run the application with Air:
For Windows:
air
For Linux:
air -c .air.linux.toml
-
Start the application and database:
docker-compose up
-
For background execution:
docker-compose up -d
- Create new API handlers in the
api/
directory, following the module pattern - Update routes in the appropriate module initialization in
startup/
- Add any required models and database migrations
- Test your changes locally
- Place business logic in appropriate modules
- Follow Go best practices for error handling and documentation
- Write tests for new functionality
Run tests using:
go test ./...
Build the executable binary:
For Windows:
go build -o app.exe cmd/main.go
For Linux:
go build -o app cmd/main.go
-
Build the Docker image:
docker build -t crud-server .
-
Run the container:
docker run -p 8888:8888 --env-file .env crud-server
For production deployment, you should:
- Set up a proper database instance (not the Docker development instance)
- Configure all environment variables appropriately
- Use Docker or a container orchestration tool like Kubernetes
- Set up proper logging and monitoring
The server provides the following API endpoints (on the /api
route):
- Task management (exact endpoints depend on implementation)
- GET, POST, PUT, DELETE operations