Defining the To-Do API

Powerful Command-Line Applications in Go — by Ricardo Gerardi (19 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Organizing Your Code | TOC | Creating the Initial To-Do Command-L ine Tool 👉

To start your to-do tracking tool, you’ll implement some business logic and an API to deal with to-do items.

In this version of the API, you’ll implement two new custom types:

item:
This type represents a single to-do item. You’ll implement this type using a Go struct. A struct is a custom Go type composed of one or more named elements, or fields. Each field consists of a name and a type, each representing a property of the struct. You can find more information about Go structs in the official documentation.[13] This type won’t be exported, so it can’t be used by API users directly.

List:
This type represents a list of to-do items. It’s implemented by a slice of instances of the type item. This type is exported and visible outside the package.

These custom types represent the data about the to-do items your application manages. To implement actions, like adding an item to the list or saving the list, you’ll use methods associated with the List type. A method is a function that’s associated with a specific type. This association allows the function to execute directly on the type’s data. You can learn more about methods in the official documentation.[14]

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.