A customer management API built with Go and the Ergo framework. This project demonstrates actor-based concurrency using Ergo to manage customer data through a RESTful API.
- Actor-based Architecture: Uses the Ergo framework for actor-based concurrency
- RESTful API: Full CRUD operations for customer management
- Persistent Storage: Uses bbolt for persistent customer data storage
- Concurrent Request Handling: Actor pattern ensures safe concurrent access to customer data
- Go 1.21 or higher
- Basic understanding of REST APIs
Clone the repository and build the application:
git clone https://github.com/richardcase/ergo-test.git
cd ergo-test
go mod download
go build -o customer-apiStart the server:
./customer-apiThe server will start on port 8080. You should see output similar to:
Ergo node started: 'customer-api@localhost'
Customer actor started with bbolt database: customers.db
HTTP server listening on :8080
API Endpoints:
GET /api/customers - List all customers
GET /api/customers/{id} - Get a customer by ID
POST /api/customers - Create a new customer
PUT /api/customers/{id} - Update a customer
DELETE /api/customers/{id} - Delete a customer
GET /health - Health check
Customer data is persisted in the customers.db file.
GET /healthGET /api/customersGET /api/customers/{id}POST /api/customers
Content-Type: application/json
{
"id": "1",
"name": "John Doe",
"email": "[email protected]",
"phone": "555-1234"
}PUT /api/customers/{id}
Content-Type: application/json
{
"name": "John Updated",
"email": "[email protected]",
"phone": "555-9999"
}DELETE /api/customers/{id}# Create a customer
curl -X POST http://localhost:8080/api/customers \
-H 'Content-Type: application/json' \
-d '{"id":"1","name":"John Doe","email":"[email protected]","phone":"555-1234"}'
# List all customers
curl http://localhost:8080/api/customers
# Get a specific customer
curl http://localhost:8080/api/customers/1
# Update a customer
curl -X PUT http://localhost:8080/api/customers/1 \
-H 'Content-Type: application/json' \
-d '{"name":"John Updated","email":"[email protected]","phone":"555-9999"}'
# Delete a customer
curl -X DELETE http://localhost:8080/api/customers/1A demo script is provided to showcase all API operations:
./demo.shThis script demonstrates:
- Health check
- Listing empty customers
- Creating customers
- Listing all customers
- Getting a specific customer
- Updating a customer
- Deleting a customer
- Error handling for non-existent customers
The application uses an actor-based architecture powered by the Ergo framework:
- Ergo Node: Provides the actor system runtime
- Customer Actor: A goroutine-based actor that handles all customer operations through channels
- API Handler: HTTP handlers that communicate with the Customer Actor
- bbolt Store: Persistent customer data storage using bbolt (a key-value database)
HTTP Request → API Handler → Customer Actor → bbolt Store
↓
HTTP Response ← API Handler ← Customer Actor ← bbolt Store
The Customer Actor pattern ensures:
- Thread-safe access to customer data
- Sequential processing of requests
- Isolation of business logic from HTTP concerns
.
├── main.go # Application entry point and Ergo node setup
├── customer.go # Customer actor and data models
├── api.go # HTTP API handlers
├── demo.sh # Demo script showcasing all API operations
├── go.mod # Go module dependencies
├── go.sum # Go module checksums
├── .gitignore # Git ignore file
└── README.md # This file
- Ergo Framework - Actor-based framework for Go
- bbolt - An embedded key/value database for Go
This project is for demonstration purposes.