Search⌘ K
AI Features

Defining the To-Do API

Explore how to create a to-do list API in Go that manages tasks through a command-line interface. Understand input methods, data structures like structs and slices, and implement key functions such as adding and saving items. This lesson also covers proper code organization and error handling for building reusable CLI applications.

Unlike with a graphical program, the user of a CLI tool generally provides all the input and parameters required for the tool to work upfront. The tool uses that input to do its job and provides the results back to the user as text output on the screen. When an error occurs, a CLI tool usually provides details about it in a way that’s easy and practical for the user to understand or potentially filter out.

Managing a to-do list

In this chapter, we’ll get comfortable working with input and output as we build a command-line tool for managing a list of to-do items. This tool will let us keep track of items left in a project or activity. The tool will save the list of items in a file using the JSON format.

To implement this tool, we’ll accept input data from our users in a variety of ways. We’ll get input from standard input (STDIN) and command-line parameters. We’ll also use environment ...