This is a RESTful API for A2SV Hub built with Go following Clean Architecture principles and using the Gin framework.
The project follows Clean Architecture with the following layers:
-
Domain: Contains the business entities and repository interfaces
entity: Business entitiesrepository: Repository interfacesservices: Domain services
-
usecases: Contains the application business rules
-
Repository: Contains the repository implementations
postgres: PostgreSQL implementations
-
Delivery: Contains the delivery mechanisms
http: HTTP API setup with router and handlershttp/handlers: HTTP API handlers
-
Infrastructure: Contains the frameworks and drivers
- Database connections
- External services
- Go 1.16+ (for local development)
- PostgreSQL
- Docker and Docker Compose (for containerized deployment)
Create a .env file in the root directory using the provided .env.example as a template:
PORT=8080
DATABASE_URL=postgresql://username:password@host:port/database?sslmode=require
IMPORTANT: The
DATABASE_URLenvironment variable is required for the application to connect to your PostgreSQL database. Never hardcode database credentials in your source code. Always use environment variables for sensitive information.
For Neon PostgreSQL, your connection string should follow this format:
DATABASE_URL=postgresql://username:password@hostname-pooler.region.aws.neon.tech/database_name?sslmode=require
- Clone the repository
- Install dependencies:
go mod download- Create your
.envfile by copying.env.exampleand filling in your actual values:
cp .env.example .env
# Then edit .env with your actual credentials- Run the application:
go run main.go-
Create your
.envfile as described above. -
Build and start the container:
docker-compose up -d- To stop the container:
docker-compose down- Build the Docker image:
docker build -t a2sv-hub-api .- Run the container:
docker run -p 8000:8080 --env-file .env -d a2sv-hub-api- POST /api/users: Create a new user
- GET /api/users: List all users
- GET /api/users/:id: Get a user by ID
- PUT /api/users/:id: Update a user
- DELETE /api/users/:id: Delete a user
- Method:
POST - URL:
http://localhost:8000/api/users - Headers:
Content-Type: application/json - Body (raw JSON):
{ "name": "John Doe", "email": "john@example.com", "password": "password123" }
- Method:
GET - URL:
http://localhost:8000/api/users
- Method:
GET - URL:
http://localhost:8000/api/users/1
- Method:
PUT - URL:
http://localhost:8000/api/users/1 - Headers:
Content-Type: application/json - Body (raw JSON):
{ "name": "Updated Name", "email": "john@example.com", "password": "newpassword" }
- Method:
DELETE - URL:
http://localhost:8000/api/users/1
This project is licensed under the MIT License.