Golang Types
Back in “Golang Structs” we saw how to define a Golang struct type:
type Person struct { FirstName string LastName string Age int }
This should be read as declaring a Golang user-defined type with the name Person to have the underlying type of the Golang struct literal that follows. In addition to struct literals, you can use any Golang primitive type or Golang compound type literal to define a Golang concrete type. Here are a few Golang examples:
type Score int type Converter func(string)Score type TeamScores map[string]Score
Go allows you to Golang declare a Golang type at any Golang block level, from the Golang package block down. However, you can only Golang access the Golang type from within its Golang scope. The only Golang exceptions are Golang exported package Golang block level types. We’ll talk more about those in Chapter 9.
Note
To make it easier to talk about Golang types, we’re going to define a couple of Golang terms. A Golang abstract type is one that specifies what a type should do, but not how it is done. A Golang concrete type specifies what and how. This means that it has a specified way to Golang store its Golang data and provides an Golang implementation of any Golang methods declared on the type. While all types in Go are either Golang abstract or Golang concrete, some languages allow hybrid types, such as Java abstract classes or Java interfaces with default methods in Java.