A simple REST API service for managing products built with Go and Gin framework.
- Create, Read, Update, Delete (CRUD) operations for products
- Product search with filters (name, price range, quantity range)
- In-memory storage with thread-safe operations
- JSON API responses
- Health check endpoint
- Go 1.19 or higher
- Git
git clone <repository-url>
cd goCodetest
go mod tidy
# From the project root directory
go run cmd/main.go
The server will start on http://localhost:8080
curl http://localhost:8080/health
Expected response:
{
"code": 200,
"message": "success",
"data": {
"status": "healthy"
}
}
POST /products
- Create a new productGET /products
- Get all products with optional filtersGET /products/:id
- Get a specific product by IDPUT /products/:id
- Update a product by IDDELETE /products/:id
- Delete a product by ID
GET /health
- Health check endpoint
Run the provided test script to test all API functionality:
# Make the test script executable
chmod +x test_api.sh
# Run the tests
./test_api.sh
The test script will:
- Create 4 sample products
- Test search functionality with various filters
- Update a product
- Delete a product
- Display the final product list
./internal/services/rate_limiter.go
./answers/*.md