Lab 15: Capstone — storecli

Objective

Build a complete, production-quality Go CLI tool: argument parsing, file I/O, JSON persistence, HTTP API, concurrent workers, context cancellation, and a full test suite — applying all concepts from Labs 01–14.

Background

This capstone builds storecli — an inventory management CLI written in pure Go. It demonstrates: structs (Lab 4), interfaces (Lab 5), goroutines (Lab 7), error handling (Lab 8), file I/O (Lab 10), HTTP (Lab 11), testing (Lab 12), context (Lab 13), and generics (Lab 14).

Time

60 minutes

Prerequisites

  • Labs 01–14

Tools

  • Docker image: zchencow/innozverse-go:latest


Lab Instructions

Step 1: Data Types & Interfaces

💡 Returning (*Product, error) from NewProduct is the Go constructor convention. It validates input and returns a ready-to-use value OR an error explaining why creation failed. The caller is forced to handle the error — no silent bad state.

📸 Verified Output:


Step 2: In-Memory Store with Generics

📸 Verified Output:


Step 3: CLI Argument Parser

📸 Verified Output:


Step 4: Output Formatters

📸 Verified Output:


Steps 5–8: JSON Persistence, Stats, Concurrent Fetch, Capstone Main

📸 Verified Output:


Verification

Summary

Lab
Applied in capstone

01

Variables, constants, fmt

02

Functions, closures, variadic

03

Slices, maps, sorting

04

Structs, methods, embedding

05

Repository interface

06

Pointers, struct mutation

07

Goroutines, concurrent price check

08

Custom errors, validation

09

Standard library: time, math, sort

10

JSON store persistence to file

11

HTTP patterns, REST design

12

Testable design (separation of concerns)

13

Context with timeout for price fetch

14

Generic filter functions

Further Reading

Last updated