Julian Wiley

Basic Types

<!-- String Type -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Strings" >}}

str := "Hello"

Multiline string

str := `Multiline
string`

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}

<!-- Number Types -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Numbers" >}}

Typical types

num := 3          // int
num := 3.         // float64
num := 3 + 4i     // complex128
num := byte('a')  // byte (alias for uint8)

Other Types

var u uint = 7        // uint (unsigned)
var p float32 = 22.7  // 32-bit float

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}

<!----------- Arrays ------>

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Arrays" >}}

// var numbers [5]int
numbers := [...]int{0, 0, 0, 0, 0}

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}

<!-- Pointers -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note size="medium" title="Pointers">}}

func main () {
  b := *getPointer()
  fmt.Println("Value is", b)
func getPointer () (myPointer *int) {
  a := 234
  return &a
a := new(int)
*a = 234

Pointers point to a memory location of a variable. Go is fully garbage-collected.

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}

<!-- Type Conversion -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Type Conversion" >}}

i := 2
f := float64(i)
u := uint(i)

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}

<!-- Slice -->

WARNING: Unported Hugo shortcode (manual conversion needed): {{< note title="Slice" >}}

slice := []int{2, 3, 4}
slice := []byte("Hello")

WARNING: Unported Hugo shortcode (manual conversion needed): {{< /note >}}