Basics of Go Programming Language
var name string = "John"
var m map[string]string
a := make(map[string]string) a := map[string]string{"key1":"value1", "key2":"value2"}
var a [5]int // array of 5 integers a := [5]int{1,2,3,4,5} // array of 5 integers initialized with values
var s []int // slice of integers a := make([]int, 5) // slice of integers initialized with 5 zeros a := []int{1,2,3,4,5} // slice of integers initialized with values
var a, b, c int = 1, 2, 3
var ( a string = "initial" b int )
type person struct { name string age int }
a := person{name: "John", age: 30} a := person{"John", 30}
a.name = "John" a.age = 30
bool string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr byte // alias for uint8 rune // alias for int32 // represents a Unicode code point float32 float64 complex64 complex128
== equal to != not equal to < less than <= less than or equal to
greater than = greater than or equal to
&& and || or ! not
if x > 10 { // do something } else if x < 5 { // do something else } else { // do yet another thing }
switch x { case 1: // do something case 2: // do something else default: // do yet another thing //optional }
- addition
- subtraction
- multiplication / division % modulus ++ increment by 1 -- decrement by 1
a := make([]int, 5) // slice of integers initialized with 5 zeros a := []int{} a := []int{1,2,3,4,5}