This project is a simple RESTful API for managing student records using Go, Chi router, and PostgreSQL. All content are created by Cursor AI.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/khoilu-1512/go-chi-cursor-example.git cd go-chi-cursor-example
-
Create a
.env
file in the root directory with the following content:DB_HOST=db DB_USER=your_username DB_PASSWORD=your_password DB_NAME=your_database_name DB_SSLMODE=disable
Replace
your_username
,your_password
, andyour_database_name
with your desired values. -
Build and run the application using Docker Compose:
docker-compose up --build
-
The API will be available at
http://localhost:8080
GET /students
: Retrieve all studentsPOST /students
: Create a new studentGET /students/{id}
: Retrieve a specific studentPUT /students/{id}
: Update a specific studentDELETE /students/{id}
: Delete a specific student
main.go
: Entry point of the applicationstudent_handlers.go
: Contains handlers for student-related operationsDockerfile
: Defines the Docker image for the Go applicationdocker-compose.yml
: Defines the multi-container Docker environmentinit.sql
: Initializes the database schema and inserts sample data
To stop the application, use:
docker-compose down
This will stop and remove the containers. To also remove the volumes, use:
docker-compose down -v
This README provides instructions on how to set up and run the project locally using Docker and Docker Compose. It includes information about prerequisites, getting started steps, API endpoints, project structure, and how to stop the application.