Welcome! Today, we'll explore building a simple address book application using Go and its built-in map
type. Maps in Go are versatile and allow us to manage collections of key-value pairs efficiently. This task will help you understand how to handle map operations in Go, focusing on adding, retrieving, and deleting entries. By the end of this lesson, you'll have a solid grasp of these fundamental operations and understand the practical significance of Go's map in real-world applications.
In this task, we will implement three functions to manage our address book:
func (ab *AddressBook) addContact(name, phoneNumber string) bool
: Adds a new contact. Returnsfalse
if the contact already exists; otherwise, adds the contact and returnstrue
. In this task, phone numbers are immutable, so overwriting an existing contact's number is not allowed.func (ab *AddressBook) getContact(name string) string
: Retrieves the phone number for a givenname
. Returns an empty string if the contact does not exist.func (ab *AddressBook) deleteContact(name string) bool
: Deletes a contact with the givenname
. Returnstrue
if the contact exists and is deleted, otherwise.
