Conclusion: Simplicity That Improves Life
Introduction
Throughout this course, you’ve learned how Go handles logic, structure, and performance with minimalism and clarity. Now, we close with a project that embodies the Go philosophy: simple tools that make life easier.
This final project is a local expense tracker. It doesn’t rely on databases or cloud services. It’s fast, lightweight, and respectful of your data. It saves your expenses in a local file (CSV or JSON), and gives you a clean summary of your spending.
Goal
Create a command-line tool in Go that:
- Accepts expense entries (date, category, amount, description)
- Saves them to a local file (CSV or JSON)
- Displays a summary of total spending per category
- Keeps the code readable, maintainable, and beginner-friendly
Project Structure
1. Data Model
type Expense struct {
Date string `json:"date"`
Category string `json:"category"`
Amount float64 `json:"amount"`
Description string `json:"description"`
}
2. Input Function
func getExpenseInput() Expense {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Date (YYYY-MM-DD): ")
date, _ := reader.ReadString('\n')
fmt.Print("Category: ")
category, _ := reader.ReadString('\n')
fmt.Print("Amount: ")
var amount float64
fmt.Scanf("%f\n", &amount)
fmt.Print("Description: ")
description, _ := reader.ReadString('\n')
return Expense{
Date: strings.TrimSpace(date),
Category: strings.TrimSpace(category),
Amount: amount,
Description: strings.TrimSpace(description),
}
}
3. Save to File (CSV or JSON)
func saveExpenseCSV(exp Expense, filename string) {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer file.Close()
writer := csv.NewWriter(file)
defer writer.Flush()
record := []string{exp.Date, exp.Category, fmt.Sprintf("%.2f", exp.Amount), exp.Description}
writer.Write(record)
}
func saveExpenseJSON(exp Expense, filename string) {
var expenses []Expense
data, err := os.ReadFile(filename)
if err == nil {
json.Unmarshal(data, &expenses)
}
expenses = append(expenses, exp)
updatedData, _ := json.MarshalIndent(expenses, "", " ")
os.WriteFile(filename, updatedData, 0644)
}
4. Summary Function
func showSummary(filename string) {
data, err := os.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
var expenses []Expense
json.Unmarshal(data, &expenses)
summary := make(map[string]float64)
for _, exp := range expenses {
summary[exp.Category] += exp.Amount
}
fmt.Println("\nSpending Summary:")
for cat, total := range summary {
fmt.Printf("- %s: $%.2f\n", cat, total)
}
}
5. Main Function
func main() {
filename := "expenses.json"
exp := getExpenseInput()
saveExpenseJSON(exp, filename)
showSummary(filename)
}
What You’ve Learned
- How to structure a Go program with clarity
- How to read user input and validate it
- How to save structured data to local files
- How to summarize and display useful insights
- How simplicity can be powerful when done right
Why “Simplicity That Improves Life”?
Because tools don’t need to be complex to be helpful. This project doesn’t use databases, servers, or frameworks. It’s just Go, files, and logic. And yet, it solves a real problem—tracking your spending—with elegance and speed.
What’s Next?
- Add support for CSV export
- Build a web interface with
Go + HTMX - Add filters by date or category
- Create a monthly report generator
- Package it as a CLI tool with flags (
cobraorurfave/cli)
Thank You
Thank you for walking through this course. I hope you’ve discovered that Go isn’t just fast—it’s freeing. And that simplicity, when done well, is a form of respect.
Disclaimer
This project is for educational purposes only. It does not include encryption, authentication, or cloud backup. Use responsibly and do not store sensitive financial data without proper safeguards.
