Files
go-cart-actor/README.md
2025-10-10 06:45:23 +00:00

2.1 KiB

Go Cart Actor

A distributed cart management system using the actor model pattern.

Prerequisites

  • Go 1.24.2+
  • Protocol Buffers compiler (protoc)
  • protoc-gen-go and protoc-gen-go-grpc plugins

Installing Protocol Buffers

On Windows:

winget install protobuf

On macOS:

brew install protobuf

On Linux:

# Ubuntu/Debian
sudo apt install protobuf-compiler

# Or download from: https://github.com/protocolbuffers/protobuf/releases

Installing Go protobuf plugin

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

Working with Protocol Buffers

Generating Go code from proto files

After modifying any proto (proto/messages.proto, proto/cart_actor.proto, proto/control_plane.proto), regenerate the Go code (all three share the unified messages package):

cd proto
protoc --go_out=. --go_opt=paths=source_relative \
       --go-grpc_out=. --go-grpc_opt=paths=source_relative \
       messages.proto cart_actor.proto control_plane.proto

Protocol Buffer Messages

The proto/messages.proto file defines the following message types:

  • AddRequest - Add items to cart (includes quantity, sku, country, optional storeId)
  • SetCartRequest - Set entire cart contents
  • AddItem - Complete item information for cart
  • RemoveItem - Remove item from cart
  • ChangeQuantity - Update item quantity
  • SetDelivery - Configure delivery options
  • SetPickupPoint - Set pickup location
  • PickupPoint - Pickup point details
  • RemoveDelivery - Remove delivery option
  • CreateCheckoutOrder - Initiate checkout
  • OrderCreated - Order creation response

Building the project

go build .

Running tests

go test ./...

Important Notes

  • Always regenerate protobuf Go code after modifying any .proto files (messages/cart_actor/control_plane)
  • The generated messages.pb.go file should not be edited manually
  • Make sure your PATH includes the protoc-gen-go binary location (usually $GOPATH/bin)