A simple log handler
To set up the project, follow the steps below:
- Clone the repository:
git clone https://github.com/MrRancy/LogAssignment.git - Install dependencies:
go mod tidy - Build the project:
go build
To run the application, execute the compiled binary:
./logAssignment- Endpoint:
/healthz - Method: GET
- Description: Check the health status of the application.
- Handler Function:
Health
- Endpoint:
/log - Method: POST
- Description: Receive and process log payloads.
- Handler Function:
LogHandler - Middleware:
LogMiddleware
The log endpoint expects the log payload to be in JSON format. The payload should adhere to the following structure:
{
"user_id": 1,
"total": 1.65,
"title": "delectus aut autem",
"meta": {
"logins": [
{
"time": "2020-08-08T01:52:50Z",
"ip": "0.0.0.0"
}
],
"phone_numbers": {
"home": "555-1212",
"mobile": "123-5555"
}
},
"completed": false
}If the JSON payload is invalid, a 400 Bad Request response will be returned with the error message.
The logging controller (Controller) provides the following functions:
- Function:
Health - Description: Returns a simple "OK" response indicating the health of the application.
- Function:
LogHandler - Description: Handles incoming log payloads, validates the JSON format, and stores the logs in the cache.
- Response Format:
{
"Message": "Log payload received successfully",
"Data": [
// Array of logged data
]
}- Function:
LogMiddleware - Description: Middleware function to handle logging-related tasks before reaching the
LogHandler. This can include logging incoming requests or performing additional validations.
List any external dependencies or libraries used in the project.
github.com/gin-gonic/gin v1.9.1
go.uber.org/zap v1.26.0