Steps

Assuming a fresh start


Goroutines


Functions

Declaration

func <name>(arg <type>) <return type> {
//body
return <val>
}
func firstFn(arg1 int, arg2 int) int {
val := arg1 + arg2
fmt.Println("I am a method and my value is : ", val)
return val
}

Calling a function


Pointers

Initialize a pointer

arrA := [...] int{1, 3, 5}
var b *int = &arrA[0]

Modifying the pointer referenced value

arrA := [...] int{1, 3, 5}
var b *int = &arrA[0]
fmt.Println("value : "…


Map

Method 1
variable := map[<key type>]<value type> {comma separated key,value}
emptyMap := map[string]int{}
fmt.Println(emptyMap)
Result
map[]
ORarrMap := map[[3]string]int{}OR
statePop := map[string]int {
"UP": 235,
"Maharashtra": 200,
"Delhi": 150,
"MP": 175,
"Rajasthan": 165,
"Karnataka": 150,
}
fmt.Printf("statewise population map : %v", statePop)…


Arrays

Method 1
<variable> := [size of array] <type> {valueset}
This will initialize an array of size as specified in - <size of array>
grades := [3] int{97, 98, 99}
Method 2
<variable> := [...] <type> {valueset}
This will initialize an array with size as in the number of elements in the valueset.
grades := [...] int{97,98, 99, 100}
size - 4
Method 3
var <variable> [size of array] <type>
This…


DataTypes

var checkIfTrue bool = true
fmt.Printf("%v, %T\n", checkIfTrue, checkIfTrue)
var postId int = 10
commentId := 50
f := 3.14
fmt.Printf("%v, %T\n", f, f)
f = 3.14E-2
fmt.Printf("%v…

Prateek Gupta

Senior Software Developer from India. Fancy learning and building stuff. Making a habit to share knowledge via blogs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store