Predeclared types
February 16, 2023
Types
The language predeclares certain type names. Others are introduced with type declarations or type parameter lists. Composite types—array, struct, pointer, function, interface, slice, map, and channel types—may be constructed using type literals.
Type declarations, type parameter lists, and type aliases are coming up later, so today we’re focused on the predeclared types.
The list of predclared types would appear near the beginning of most intro to Go books (I would know, I just read and reviewed 11 of them!). In the Go spec, they appear about a third of the way through. So we’re jumping ahead to enumerate them. These are all of the predeclared, or “basic” types in Go.
Type Name | Description |
---|---|
any |
Alias for interface{} , the empty interface |
bool |
Boolean, possible values are true and false |
byte |
Alias for uint8 |
comparable |
Denotes all non-interface types that are strictly comparable |
complex64 |
A 64-bit complex number |
complex128 |
A 128-bit complex number |
error |
Interface type used to report errors |
float32 |
32-bit floating point number |
float64 |
64-bit floating point number |
int |
A 32- or 64-bit signed integer* |
int8 |
An 8-bit signed integer |
int16 |
A 16-bit signed integer |
int32 |
A 32-bit signed integer |
int64 |
A 64-bit signed integer |
rune |
Alias for int32 , A Unicode codepoint |
string |
A string of Unicode characters |
uint |
A 32- or 64-bit unsigned integer* |
uint8 |
An 8-bit unsigned integer |
uint16 |
A 16-bit unsigned integer |
uint32 |
A 32-bit unsigned integer |
uint64 |
A 64-bit unsigned integer |
uintptr |
An unsigned integer large enough for a pointer value* |
* The size of these types is architecture-dependent.
Quotes from The Go Programming Language Specification, Version of January 19, 2023
Related Content

Empty structs
We finally we have enough knowledge for the EBNF format not to seem completely foreign, so let’s jump back and take a look at that, with the examples provided in the spec… Struct types … StructType = "struct" "{" { FieldDecl ";" } "}" . FieldDecl = (IdentifierList Type | EmbeddedField) [ Tag ] . EmbeddedField = [ "*" ] TypeName [ TypeArgs ] . Tag = string_lit . // An empty struct.

Struct tags
Struct types … A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. An empty tag string is equivalent to an absent tag. The tags are made visible through a reflection interface and take part in type identity for structs but are otherwise ignored. struct { x, y float64 "" // an empty tag string is like an absent tag name string "any string is permitted as a tag" _ [4]byte "ceci n'est pas un champ de structure" } // A struct corresponding to a TimeStamp protocol buffer.

Struct method promotion
Yesterday we saw an example of struct field promotion. But methods (which we haven’t really discussed yet) can also be promoted. Struct types … Given a struct type S and a named type T, promoted methods are included in the method set of the struct as follows: If S contains an embedded field T, the method sets of S and *S both include promoted methods with receiver T. The method set of *S also includes promoted methods with receiver *T.