A rune is Go’s alias for int32, used when an integer represents a Unicode character rather than arbitrary numeric data. It represents the character value independently of its encoded byte length. section 3.1 section 3.8.6
Use runes when character-oriented behavior matters:
- Range over a string to receive one rune per character while retaining the byte index where that character begins. section 3.8.5
- Convert a string to []rune when indexes should represent character positions rather than byte offsets. section 3.8.7
- Pass runes to unicode and unicode/utf8 functions to classify characters, change case, or inspect encoded length. section 3.8.6
Iterate Unicode characters
unicodeCharStr := "地鼠" for i, r := range unicodeCharStr { fmt.Printf("%d:%s ", i, string(r)) } // Output: 0:地 3:鼠 characters := []rune(unicodeCharStr) // The rune slice indexes the characters as 0 and 1. section 3.8.5 section 3.8.7
Inspect a rune
for _, r := range "À" { fmt.Println(utf8.RuneLen(r)) if unicode.IsLetter(r) && unicode.IsUpper(r) { fmt.Println(string(unicode.ToLower(r))) } } // Output includes: 2 and à section 3.8.6
Table 3.1 Predeclared integer types
| Type name |
Description |
Value vange |
|---|---|---|
|
|
Signed integers |
32 or 64 bits, depending on your architecture |
|
|
Signed 8-bit integers |
-128 to 127 |
|
|
Signed 16-bit integers |
-32,768 to 32,767 |
|
|
Signed 32-bit integers |
-2,147,483,648 to 2,147,483,647 |
|
|
Signed 64-bit integers |
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
|
|
Unsigned integers |
32 or 64 bits, depending on your architecture |
|
|
Unsigned 8-bit integers |
0 to 255 |
|
|
Unsigned 16-bit integers |
0 to 65,535 |
|
|
Unsigned 32-bit integers |
0 to 4,294,967,295 |
|
|
Unsigned 64-bit integers |
0 to 18,446,744,073,709,551,615 |
|
|
An alias for |
|
|
|
An alias for |
Compare rune with Go’s other predeclared integer aliases and fixed-width integer types. section 3.1



