-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (31 loc) · 838 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
fmt.Println("Functions in Golang")
fmt.Println("A random number popped up:", getRandomNumber(200))
fmt.Println("Adding two random nums:", add(int(getRandomNumber(6)), int(getRandomNumber(20))))
integer, integerDesc := returnTwoValues()
fmt.Println("The integer is:", integer, "and description is", integerDesc)
func() {
fmt.Println("IIFE: Get's immediately invoked")
}()
someFunction := func() string { // Anonymous function
return "Hello World"
}
fmt.Println(someFunction())
}
func getRandomNumber(to int32) int32 {
source := rand.NewSource(time.Now().UnixNano())
generator := rand.New(source)
return generator.Int31n(to) + 1
}
func add(x int, y int) int {
return x + y
}
func returnTwoValues() (int, string) {
return 12, "Returned 12"
}