This project is a simple CRUD (Create, Read, Update, Delete) application for managing student records using GoLang and MongoDB. It provides a RESTful API to perform operations on a student database.
- Create a new student record
- Retrieve a student record by ID
- Retrieve all student records
- Update an existing student record by ID
- Delete a student record by ID
- Delete all student records
- GoLang
- MongoDB
- Gorilla Mux for HTTP routing
- UUID for unique student IDs
-
Clone the repository:
git clone https://github.com/swarraaa/GoLang_Students_DB_CRUD.git cd GoLang_Students_DB_CRUD
-
Install Go dependencies:
go mod tidy
-
Create a
.env
file:Create a
.env
file in the project root and add your MongoDB URI and database information:MONGO_URI=mongodb://localhost:27017 DB_NAME=your_db_name COLLECTION_NAME=students
-
Run the application:
go run main.go
-
Access the API:
The server will be running on
http://localhost:4444
. You can use tools likecurl
or Postman to interact with the API endpoints.
- GET
/health
- Check if the server is running - POST
/student
- Create a new student - GET
/student/{id}
- Retrieve a student by ID - GET
/student
- Retrieve all students - PUT
/student/{id}
- Update a student by ID - DELETE
/student/{id}
- Delete a student by ID - DELETE
/student
- Delete all students
main.go
- Entry point of the applicationmodel/
- Contains data modelsrepository/
- Contains database operationsusecase/
- Contains business logic and API handlers