[READ-ONLY] Mirror of https://github.com/andrioid/golang-intro-deck. Making a short intro for Go at work
golang-intro-deck-tybwmsvtml.now.sh/#0
3.7 kB
227 lines
1import { Head, Appear, Image, Link } from "mdx-deck";
2export { default as theme } from "./theme";
3import { CodeSurfer } from "mdx-deck-code-surfer";
4import codeTheme from "prism-react-renderer/themes/vsDark";
5
6# PARK PARK
7
8## GO GO!
9
10<img
11 src={require("file-loader!./img/network.svg")}
12 style={{ height: "30vh" }}
13/>
14
15---
16
17## Topics covered
18
19- Why Go?
20- Hello World
21- Web services
22- Web services with JSON
23- SQL
24- Directory structure
25- Useful links
26
27---
28
29## Topics _not_ covered
30
31- Language features
32- Testing
33
34---
35
36## Why Go?
37
38<Appear>
39 <img
40 src={require("!file-loader!./img/gotham.svg")}
41 style={{ width: "80vw" }}
42 />
43</Appear>
44
45---
46
47## My favourite things
48
491. Opinionated as #"!
502. Typed
513. Best standard-library
524. Interface
535. Great community
54
55---
56
57## For PARKPARK
58
591. Reliable
602. Created for large teams
613. Will be here in 5 years, 10 probably
624. Large stdlib, less dependency on 3rd party libraries
635. Easy to learn from a PHP background
646. Has all the libraries we need
65
66---
67
68## Other things
69
70- Concurrency
71- Tooling
72- OOP, but not Java OOP
73- Cute mascot
74
75<img
76 src={require("!file-loader!./img/heart-hug.svg")}
77 style={{ height: "40vh" }}
78/>
79
80---
81
82## Before we start
83
84### Godoc
85
86- https://godoc.org
87
88```bash
89$ go doc
90```
91
92---
93
94<CodeSurfer
95 title="hello.go"
96 code={require("!raw-loader!./code/hello/hello.go")}
97/>
98
99---
100
101<CodeSurfer
102 title="webservice.go"
103 code={require("!raw-loader!./code/webservice/webservice.go")}
104/>
105
106---
107
108<CodeSurfer
109 title="jsonservice.go"
110 code={require("!raw-loader!./code/jsonservice/jsonservice.go")}
111/>
112
113---
114
115## jsonservice.go
116
117```bash
118$ go run code/jsonservice/jsonservice.go
119```
120
121```bash
122$ curl http://localhost:3022
123Welcome to PARKPARK!
124$ curl http://localhost:3022/greet
125Invalid input
126$ curl -X POST -d '{"name" : "PARKPARK"}' http://localhost:3022/greet
127{"text":"Hello PARKPARK"}
128$ curl -X POST -d '{"name" : "PARKPARK"}' http://localhost:3022/greet
129{"text":"Hello PARKPARK"}
130```
131
132---
133
134<CodeSurfer
135 title="sql.go"
136 showNumbers={true}
137 code={require("!raw-loader!./code/sql/sql.go")}
138 steps={[
139 { lines: [6], notes: "SQL interface from stdlib" },
140 { lines: [10], notes: "SQL driver" },
141 { lines: [14], notes: "Connect and configure" },
142 { range: [20, 27], notes: "Create table" },
143 { range: [29, 32], notes: "Insert row" },
144 { range: [34, 48], notes: "Query" },
145 { notes: "The entire example" }
146 ]}
147/>
148
149---
150
151## From development to production
152
153- Just a single binary (and assets)
154- You don't need a web-server
155- You don't need rewrite rules
156
157---
158
159## Development
160
161- Start locally.
162- Use ENV vars to configure
163- You probably don't need Docker
164- go run cmd/myawesomeproject.go
165- go build ./...
166- go install
167- go test ./...
168
169---
170
171## Production
172
173- A very slim Docker container
174- Deployed to our Kubernetes cluster
175- Using Gitlab-CI to automatically build
176
177---
178
179## Standard Code Layout
180
181- `/git/awesomesauce/`
182- `/git/awesomesauce/cmd`
183- `/git/awesomesauce/pkg`
184- `/git/awesomesauce/internal`
185
186https://github.com/golang-standards/project-layout
187
188---
189
190## Starting a new project
191
192### Pre Go 1.11
193
194`$GOPATH` and what not
195
196### Now
197
198```
199cd ~/git/awesomesauce
200go mod init awesomesauce
201go get gitlab.com/fancypants/fancypantslib
202```
203
204Your dependencies are now stored in `go.mod` and version locked by `go.sum`
205
206You don't need to store your code in `~/go/src/` anymore
207
208---
209
210## API and other services
211
212### Server
213
214- gqlgen: GraphQL schema-first codegen
215
216### Client
217
218---
219
220## Resources
221
222- Go Doc (again): https://godoc.org
223- Go Web: https://gowebexamples.com/
224- Go By Example: https://gobyexample.com/
225- JustForFunc YT Channel: https://www.youtube.com/channel/UC_BzFbxG2za3bp5NRRRXJSw
226- Awesome Go: https://awesome-go.com/
227- Level Up? Gophercises! https://gophercises.com/