Go Tutorial: Capstone: Library CLI
Build a small book catalog in the terminal — structs, maps, functions, errors, and formatted output in one program that grows step by step.
One project, many skills
This is a **longer capstone**: each step extends the same program. Your editor **carries code forward** so it feels like shipping a real CLI.
You will model books, store them in a map, search, check out, return, print tables, and (in later steps) drive a simple menu.
### Running menu steps
Later steps use `fmt.Scanln` to read choices like a real terminal app. **Run & check** in the browser still validates your code with pattern checks; to type menu options interactively, copy the program and run it with `go run .` on your computer.
What you'll learn in this Go capstone: library cli tutorial
This interactive Go tutorial has 10 hands-on exercises. Estimated time: 55 minutes.
- Set up the Library CLI project — A CLI app that manages a library catalog using everything you've learned. Define a `Book` struct with `Title`, `Author`,…
- Add the addBook helper — Write a function `addBook(catalog map[string]Book, title, author, isbn string, available bool)` that adds a Book to the …
- Search books by title — Write `searchBooks(catalog map[string]Book, query string) []Book` that returns all books whose title contains the query …
- List all books — Write `listBooks(catalog map[string]Book)` that prints all books in a formatted table. Use `fmt.Printf("| %-30s | %-20s …
- Check out a book with error handling — Write `checkout(catalog map[string]Book, isbn string) error` that marks a book as unavailable. Return an error if the IS…
- Return a book with validation — Write `returnBook(catalog map[string]Book, isbn string) error` that marks a checked-out book as available again. Return …
- Count books by availability — Write `stats(catalog map[string]Book)` that prints: total books, available books, and checked out books. Use a loop with…
- Load sample data — Write `loadSampleData() map[string]Book` that creates a catalog with 5 pre-loaded books and returns it. Use `addBook` in…
- Interactive menu loop — Build an interactive CLI menu using `fmt.Scanln` and a `for` loop. Print options: 1. List books, 2. Search, 3. Checkout,…
- Complete the CLI with all operations — Add the remaining menu options to the switch: `case 2` (Search — prompt for a query and print results), `case 3` (Checko…
Go Capstone: Library CLI concepts covered
- One project, many skills