-
Clone the repository:
git clone https://github.com/ashuthe1/Golang-with-Integration.git cd Golang-with-Integration
-
Initialize a Go module:
go mod init FealtyX go mod tidy
-
Run the application:
go run main.go
.
├── handlers
│ └── handlers.go
├── models
│ └── models.go
├── ollama
│ └── ollama.go
├── main.go
└── README.md
-
CRUD Operations:
- Create a new student
- Get all students
- Get a student by ID
- Update a student by ID
- Delete a student by ID
-
AI Integration:
- Generate a summary of a student by ID using the LLAMA3 and Google PaLM 2 API.
-
Concurrency:
- Ensures the API can handle concurrent requests safely.
-
Error Handling:
- Appropriately handles errors such as invalid input data and non-existing students.
-
Input Validation:
- Ensures input data for creating and updating students is valid.
- Endpoint:
POST /students
- Description: Creates a new student.
- Request Body:
{ "name": "John Doe", "age": 20, "email": "john.doe@example.com" }
- cURL Command:
curl -X POST http://localhost:8080/students \ -H "Content-Type: application/json" \ -d '{"name": "John Doe", "age": 20, "email": "john.doe@example.com"}'
- Endpoint:
GET /students
- Description: Retrieves a list of all students.
- cURL Command:
curl -X GET http://localhost:8080/students
- Endpoint:
GET /students/{id}
- Description: Retrieves a student by their ID.
- cURL Command:
curl -X GET http://localhost:8080/students/1
- Endpoint:
PUT /students/{id}
- Description: Updates a student by their ID.
- Request Body:
{ "name": "Jane Doe", "age": 22, "email": "jane.doe@example.com" }
- cURL Command:
curl -X PUT http://localhost:8080/students/1 \ -H "Content-Type: application/json" \ -d '{"name": "Jane Doe", "age": 22, "email": "jane.doe@example.com"}'
- Endpoint:
DELETE /students/{id}
- Description: Deletes a student by their ID.
- cURL Command:
curl -X DELETE http://localhost:8080/students/1
- Endpoint:
GET /students/{id}/summary
- Description: Generates a summary of a student profile by ID using the Google PaLM 2 API.
- cURL Command:
curl -X GET http://localhost:8080/students/1/summary
The API uses a mutex (sync.Mutex
) to handle concurrent requests safely. This ensures data integrity when multiple requests are made simultaneously.
Errors are appropriately handled, such as:
- Returning a 400 status code for invalid input data.
- Returning a 404 status code if a student with a specified ID does not exist.
- Returning a 500 status code for internal server errors.
Input data for creating and updating students is validated to ensure it meets the required format and constraints.