You have to differentiate between the "static type" and the "dynamic type" of a variable.
Each and every variable in Go has exactly one static type. Some example:
- After declaring
a := 5the static type of
intand that is all to know about
- The static type of
ein your code is
error(because that is what
- You can be explicit about the static type like this:
var b uint16 = 9.
Now there are interface types in Go.
error is such an interface type, see Peter's answer. Some variables will have
error as their static type; your
e is an example. Now, the whole purpose of a variable of interface type is to store values of various types which implement this interface. So a interface variable which is not nil somehow "contains" an other variable (actually a value). The type of this contained value can be any one which implements the interface. The type of the contained value is the "dynamic type".
Type assertion let you extract values of this dynamic type.