Getting Started
Coffee To Go is a CLI tool designed to help you learn Golang concepts through practical coffee shop examples. Each command demonstrates different Go features in the context of a coffee shop operation.
Installation
go install github.com/petermazzocco/coffee-to-go@latest
Basic Usage
coffee learn [concept]
Replace [concept]
with one of the
available concepts like goroutines
,
interfaces
, etc.
Available Concepts
Buffer
πLearn about buffers through secret menu items.
coffee learn buffer [item-name]
Context
πLearn about the context package with delivery and pickup examples.
coffee learn context delivery [seconds]
coffee learn context pickup [code]
coffee learn context api
Generics
π§©Learn about Go generics with customer billing examples.
coffee learn generics
Goroutines
β‘Learn about goroutines with batch coffee orders.
coffee learn goroutines
Interfaces
πLearn about interfaces with coffee imports.
coffee learn interface
IO
πLearn about input/output operations with receipts.
coffee learn io create
coffee learn io read
JSON
πLearn about JSON marshal/unmarshal with distributor lists.
coffee learn json
Make
π οΈLearn about make() with seating charts and order queues.
coffee learn make seating
coffee learn make queue
[number-of-orders]
Maps
πΊοΈLearn about maps with coffee shop menus.
coffee learn maps view
coffee learn maps add [item-name] [price]
coffee learn maps remove [item-name]
Mutex
πLearn about mutexes with coffee machine usage.
coffee learn mutex
Pointers
πLearn about pointers by updating orders and creating a new coffee shop.
coffee learn pointers update
coffee learn pointers shop
Select
πLearn about select with delivery apps and payment processing.
coffee learn select delivery
coffee learn select payment [amount]
Structs
ποΈLearn about structs with customer and order data.
coffee learn structs
Switch
πLearn about switch statements with inventory checks.
coffee learn switch [item-to-check]
Example Usage
Learning Goroutines
Goroutines are a fundamental concurrency feature in Go. This example demonstrates how to use goroutines in a coffee shop scenario to handle multiple orders simultaneously.
$ coffee learn goroutines
π Processing batch orders with goroutines...
[Barista 1] Starting to make a Latte for Customer 3
[Barista 2] Starting to make an Americano for Customer 1
[Barista 3] Starting to make a Cappuccino for Customer 2
[Barista 2] Finished Americano for Customer 1 in 2.3 seconds
[Barista 3] Finished Cappuccino for Customer 2 in 3.1 seconds
[Barista 1] Finished Latte for Customer 3 in 4.5 seconds
β
All orders completed!
This example demonstrates how goroutines allow multiple tasks to run concurrently. In a coffee shop, this means multiple baristas can work on different orders at the same time!
Advanced Usage
You can combine different concepts to build more complex applications. Here are some advanced examples:
Building a Complete Coffee Order System
Combine structs, interfaces, goroutines, and JSON handling to create a complete coffee ordering system:
-
Use
structs
to define customers and orders -
Implement
interfaces
for different payment methods -
Process multiple orders concurrently with
goroutines
-
Store order history using
json
functionalities -
Protect shared resources with
mutex
Pro Tip: Explore the source code of each example to see how different Go concepts are implemented in practical scenarios. Each example is designed to demonstrate a specific concept in isolation, making it easier to understand.