-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
168 lines (133 loc) · 2.9 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package main
import (
"encoding/json"
"fmt"
"time"
"herculesgabriel/golang-playground/src/jobs"
"herculesgabriel/golang-playground/src/schemas"
mail "herculesgabriel/golang-playground/src/services/mail/implementations"
"herculesgabriel/golang-playground/src/usecases"
"herculesgabriel/golang-playground/src/utils"
)
func basicLearnings() {
divisionResult, err := utils.Divide(0, 2)
if err != nil {
utils.Logger("Error while dividing values")
}
sumResult := utils.Sum(1, 2)
sumAllResult := utils.SumAll(1, 2, 3)
fmt.Println("0 / 2 =", divisionResult)
fmt.Println("1 + 2 =", sumResult)
fmt.Println("1 + 2 + 3 =", sumAllResult)
}
func threads() {
go jobs.Countdown("second countdown", 5)
jobs.Countdown("first countdown", 10)
}
func channels() {
stringChannel := make(chan string)
go func() {
stringChannel <- "Hello,"
stringChannel <- "World!"
stringChannel <- "-"
}()
var endSignal string
for endSignal != "-" {
msg := <-stringChannel
if msg == "-" {
endSignal = msg
continue
}
time.Sleep(time.Second)
fmt.Println(msg)
}
}
func arraysAndSlices() {
var array [2]int = [2]int{1, 2}
fmt.Println(array)
var slice []int = []int{1, 2}
fmt.Println(slice)
var newSlice []int = make([]int, 2)
fmt.Println(newSlice)
}
func maps() {
var activeModules map[string]bool = make(map[string]bool)
activeModules["finances"] = true
activeModules["health"] = false
emails := map[string]string{
"bob": "[email protected]",
"kate": "[email protected]",
}
fmt.Println(activeModules)
fmt.Println(emails["bob"])
delete(emails, "kate")
_, exists := activeModules["kate"]
fmt.Println(exists)
}
func structs() {
someone := schemas.Person{
Name: "Someone",
Age: 27,
Address: schemas.Address{
City: "Curitiba",
Country: "Brasil",
},
}
city := schemas.Address{
City: "Colombo",
Country: "Brasil",
}
someoneElse := schemas.Person{
Name: "Someone Else",
Age: 26,
Address: city,
}
supermarket := schemas.Place{
Name: "Menudo",
Code: 1,
Address: city,
}
fmt.Println(someone)
fmt.Println(someoneElse)
fmt.Println(supermarket)
fmt.Println(supermarket.Address.City)
fmt.Println(supermarket.City)
fmt.Println(someone.Greeting())
}
func serializer() {
team := schemas.NewTeam()
team.AddPlayer("Bob")
team.AddPlayer("Kate")
result, _ := json.Marshal(team)
data := []byte(result)
var parsedTeam schemas.Team
json.Unmarshal(data, &parsedTeam)
fmt.Println("JSON -> " + string(result))
fmt.Println()
fmt.Print("Team -> ")
fmt.Println(parsedTeam)
}
func interfaces() {
goodMail := mail.GoodMail{}
sendPromoEmail := usecases.NewSendPromoEmail(goodMail)
sendPromoEmail.Execute("[email protected]")
}
func Runner(funcs ...func()) {
for _, fn := range funcs {
fn()
fmt.Println()
}
}
func main() {
funcs := []func(){
basicLearnings,
threads,
channels,
arraysAndSlices,
maps,
structs,
serializer,
interfaces,
}
Runner(funcs...)
}