-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-tchas2.slide
217 lines (142 loc) · 5.47 KB
/
go-tchas2.slide
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
Go-tchas
Splunk EngAcademy 2023
15 Dec 2023
Tags: go, golang, gotchas, mistakes, problems
Summary: Delving into the common traps in Go that we all inadvertently fall into from time to time.
Piotr Luciński
Principal Engineer, Secrets Management (aka Vault) Team
https://linkedin.com/in/piotr-lucinski
https://github.com/lootek
* about me
Go enthusiast since 2013
a C++ freak before
trying to forget JavaScript
Splunker since Sep 2023
becoming a DevSecOps
.image ./go-tchas2/plucinski.png _ 300
* how to start with Go
.link https://go.dev/tour/welcome/1 A Tour of Go
.link https://go.dev/doc/ Documentation - The Go Programming Language
.link https://go.dev/doc/effective_go Effective Go - The Go Programming Language
.link https://github.com/golang/go/wiki/CodeReviewComments CodeReviewComments
.link https://tip.golang.org/doc/faq Go FAQ
.link https://go101.org/article/101.html Go101
.link https://go.dev/play/ The Go Playground
* go present
.link https://pkg.go.dev/golang.org/x/tools/present Go present
.link https://go.dev/talks/ Official Go talks
* everything is a copy
- no references!
* methods, receivers
.play go-tchas2/receivers.go /^// START/,/^// END/
* methods, receivers (ctd)
.play go-tchas2/receivers-2.go /^// START/,/^// END/
* methods, receivers (ctd)
.play go-tchas2/receivers-3.go /^// START/,/^// END/
* slices
.image go-tchas2/slice.png _ 400
.caption Source: [[https://dave.cheney.net/2018/07/12/slices-from-the-ground-up][Dave Cheney - Slices from the ground up]]
* slices (ctd: init)
s := make([]byte, 5)
.image go-tchas2/slice-1.png _ 600
.caption Source: [[https://go.dev/blog/slices-intro][The Go Blog - Go Slices: usage and internals]]
* slices (ctd: reslicing)
s = s[2:4]
.image go-tchas2/slice-2.png _ 600
.caption Source: [[https://go.dev/blog/slices-intro][The Go Blog - Go Slices: usage and internals]]
* slices (ctd: leak)
.code go-tchas2/slices-digits-leak.go /^// START/,/^// END/
* slices (ctd: growing)
.play go-tchas2/slices-append.go /^// START/,/^// END/
* slices (ctd: appending)
.code go-tchas2/slices-append-2.go /^// START/,/^// END/
* slices (ctd: appending)
.play go-tchas2/slices-append-2-prints.go /^// START/,/^// END/
* maps
.image go-tchas2/maps1.jpg _ 400
.image go-tchas2/maps2.png _ 400
.caption Source: [[https://www.youtube.com/watch?v=Tl7mi9QmLns][Keith Randall - Inside the Map Implementation]]
* channels vs. mutexes
- mutex -> accessing shared data
- channels -> communication between goroutines, transferring ownership
* channels (state)
.image go-tchas2/86_state.png _ 800
.caption Source: [[https://www.ardanlabs.com/blog/2017/10/the-behavior-of-channels.html][ArdanLabs - The Behavior Of Channels]]
* channels (delivery)
.image go-tchas2/86_guarantee_of_delivery.png _ 800
.caption Source: [[https://www.ardanlabs.com/blog/2017/10/the-behavior-of-channels.html][ArdanLabs - The Behavior Of Channels]]
* channels (signaling)
.image go-tchas2/86_signaling_with_data.png _ 800
.image go-tchas2/86_signaling_without_data.png _ 800
.caption Source: [[https://www.ardanlabs.com/blog/2017/10/the-behavior-of-channels.html][ArdanLabs - The Behavior Of Channels]]
* marshal
.play go-tchas2/marshal.go /^// START/,/^// END/
.caption [[https://go.dev/play/p/-cgWn3NKo0T]]
* strings (iterating)
.play go-tchas2/strings.go /^// START/,/^// END/
* strings (performance)
.code go-tchas2/strings-append.go /^// START/,/^// END/
* shadowing
.code go-tchas2/errors-shadowing.go /^// START/,/^// END/
* shadowing (ctd)
.play go-tchas2/true-or-false.go
* errors handling
.code go-tchas2/errors-aggregation.go /^// START/,/^// END/
* timer leak
.play go-tchas2/timer.go /^// START/,/^// END/
* timer leak fixed
.play go-tchas2/timer-2.go /^// START/,/^// END/
* panic
.play go-tchas2/panic.go /^// START/,/^// END/
* panic (ctd)
.play go-tchas2/panic-2.go /^// START/,/^// END/
* for loop
.play go-tchas2/for-loop-0.go /^// START/,/^// END/
.play go-tchas2/for-loop.go /^// START/,/^// END/
.play go-tchas2/for-loop-2.go /^// START/,/^// END/
.play go-tchas2/for-loop-3.go /^// START/,/^// END/
* interfaces
.play go-tchas2/interfaces.go /^// START/,/^// END/
* interfaces (ctd)
.play go-tchas2/interfaces-2.go /^// START/,/^// END/
* interfaces (ctd)
.play go-tchas2/interfaces-3.go /^// START/,/^// END/
* defer (order)
.play go-tchas2/defer-stack.go /^// START/,/^// END/
* defer (ctd: scope)
.code go-tchas2/defer-loop.go /^// START/,/^// END/
* defer (ctd: named return params)
.play go-tchas2/defer-error.go /^// START/,/^// END/
* defer (ctd: named return params fixed)
.play go-tchas2/defer-error-fix.go /^// START/,/^// END/
* files naming
- Directory and file names that begin with `.` or `_` are ignored
- directories named `testdata` are ignored
- file names ending in `_test.go` are tests
* files naming (build tags)
- file header:
//go:build linux
// +build linux
- or file name:
server_linux.go
* files naming (build tags)
- file header:
//go:build !windows
// +build !windows
- and telling file name:
server_other.go
* low-hanging fruits
- unit tests
- race detector
- pprof
* linters
.link https://golangci-lint.run/usage/linters/ golangci-lint
.link https://vuln.go.dev/ govulncheck
* continuous learning
.link https://golangweekly.com/ Golang Weekly
.link https://tip.golang.org/blog/ The Go Blog
.link https://changelog.com/gotime The Go Time podcast
*
.image ./go-tchas2/qr.png _ 500
.caption [[https://go-talks.appspot.com/github.com/lootek/talks/go-tchas2.slide]]
.caption [[https://github.com/lootek/talks/blob/master/go-tchas2.slide]]