This guide provides information for developers who want to contribute to or extend the Coffee Order System.
- Go: Version 1.22 or higher
- Kafka: A running Kafka instance
- Git: For version control
- IDE: Any Go-compatible IDE (VSCode, GoLand, etc.)
- Clone the repository:
git clone https://github.com/yourusername/coffee-order-system.git
cd coffee-order-system- Install dependencies:
# Producer dependencies
cd producer
go mod tidy
# Consumer dependencies
cd ../consumer
go mod tidy- Set up Kafka (if not already running):
# Using Docker
docker run -d --name kafka \
-p 9092:9092 \
-e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e ALLOW_PLAINTEXT_LISTENER=yes \
bitnami/kafkaproducer/
├── config/
│ └── config.go # Configuration management
├── handler/
│ ├── handler.go # HTTP handlers
│ └── handler_test.go # Handler tests
├── kafka/
│ └── producer.go # Kafka producer
├── middleware/
│ ├── middleware.go # HTTP middleware
│ └── middleware_test.go # Middleware tests
├── config.json # Configuration file
├── go.mod # Go module file
├── go.sum # Go module checksum
└── main.go # Entry point
consumer/
├── config/
│ └── config.go # Configuration management
├── kafka/
│ └── consumer.go # Kafka consumer
├── config.json # Configuration file
├── go.mod # Go module file
├── go.sum # Go module checksum
└── main.go # Entry point
- Add a new handler function in
producer/handler/handler.go:
// NewEndpoint handles requests to the new endpoint
func (h *Handler) NewEndpoint(w http.ResponseWriter, r *http.Request) {
// Implementation
}- Register the handler in
producer/main.go:
mux.HandleFunc("/new-endpoint", h.NewEndpoint)- Add tests for the new handler in
producer/handler/handler_test.go.
- Update the configuration in
producer/config/config.goandconsumer/config/config.go:
type KafkaConfig struct {
Brokers []string `json:"brokers"`
Topic string `json:"topic"`
NewTopic string `json:"new_topic"` // Add this line
RetryMax int `json:"retry_max"`
RequiredAcks string `json:"required_acks"`
}-
Update the configuration loading in both services.
-
Add code to publish to and consume from the new topic.
Use gofmt or go fmt to format your code:
go fmt ./...Always check errors and return them to the caller:
result, err := someFunction()
if err != nil {
return err
}Use the standard log package for logging:
log.Printf("Something happened: %v", value)Write tests for all new functionality:
func TestSomething(t *testing.T) {
// Test implementation
}Run tests with:
go test ./...- Fork the repository.
- Create a new branch for your feature.
- Implement your feature.
- Write tests for your feature.
- Run all tests to ensure they pass.
- Submit a pull request.
The project does not currently have a CI/CD pipeline set up. However, you can run the following commands locally to ensure your changes meet the project standards:
# Format code
go fmt ./...
# Run tests
go test ./...
# Check for common mistakes
go vet ./...- Testing: Learn more about testing the system.
- API Reference: Explore the API endpoints.
- Kafka Integration: Learn about Kafka integration.