Chapter 4—Basic constructs and elementary data types.......................................................49
4.1. Filenames—Keywords—Identifiers..........................................................................49
4.2. Basic structure and components of a Go-program...................................................50
4.2.1 Packages, import and visibility......................................................................51
4.2.3 Comments....................................................................................................56
4.2.4 Types............................................................................................................57
4.2.5 General structure of a Go-program...............................................................58
4.2.6 Conversions..................................................................................................60
4.2.7 About naming things in Go..........................................................................60
4.3. Constants................................................................................................................60
4.4. Variables..................................................................................................................63
4.4.1 Introduction.................................................................................................63
4.4.2 Value types and reference types.....................................................................66
4.4.3 Printing........................................................................................................68
4.4.4 Short form with the := assignment operator..................................................69
4.4.5 Init-functions................................................................................................70
4.5. Elementary types and operators...............................................................................73
4.5.1. Boolean type bool........................................................................................73
4.5.2. Numerical types...........................................................................................75
4.5.2.1 ints and floats.............................................................................................75
4.5.2.2 Complex numbers.....................................................................................79
4.5.2.3 Bit operators..............................................................................................79
4.5.2.4 Logical operators........................................................................................81
4.5.2.5 Arithmetic operators.................................................................................82
4.5.2.6 Random numbers......................................................................................82
4.5.3. Operators and precedence............................................................................84
4.5.4. Aliasing types...............................................................................................84
4.5.5. Character type.............................................................................................85
4.6. Strings.....................................................................................................................86
4.7. The strings and strconv package..............................................................................88
4.7.1—Prefixes and suffixes:...................................................................................88
4.7.2—Testing whether a string contains a substring:.............................................89
4.7.3—Indicating at which position (index) a substring or character occurs
in a string:...................................................................................................89
4.7.4—Replacing a substring:................................................................................90
4.7.5—Counting occurrences of a substring:..........................................................90
4.7.6—Repeating a string:.....................................................................................90
4.7.7—Changing the case of a string:....................................................................91
4.7.8—Trimming a string:.....................................................................................92
4.7.9—Splitting a string:........................................................................................92
4.7.10—Joining over a slice:..................................................................................92
4.7.11—Reading from a string:..............................................................................93
4.8. Times and dates.......................................................................................................95
4.9. Pointers...................................................................................................................96