
The Go Workshop
By :

You can create custom types using Go's simple types as a starting point. The notation is type <name> <type>
. If we were to create an ID type based on a string, this would look like type id string
. The custom type acts the same as the type you based it on, including getting the same zero value and having the same abilities to compare with other values of the same type. A custom type is not compatible with its base type, but you can convert your custom type back into the type it's based on to allow for interaction.
In this exercise, we'll define a map and then delete an element from it using user input. Then, we'll print the now possibly smaller map to the console. Let's get started:
main.go
to it.main.go
, add the package and imports:package main import "fmt"
id
based on the string...