Coffee To Go Docs

β˜•

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:

  1. Use structs to define customers and orders
  2. Implement interfaces for different payment methods
  3. Process multiple orders concurrently with goroutines
  4. Store order history using json functionalities
  5. 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.