-
Notifications
You must be signed in to change notification settings - Fork 0
/
presentation.slide
85 lines (56 loc) · 2.7 KB
/
presentation.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
# Go Pipelines
04 August 2020
Dórian Langbeck, Filipe Reuwsaat
## A word about Go
- Go was created to **reduce the complexity** of writing server software, by bringing first-class support to concurrency
and garbage collection while providing fast compilation times, simplified syntax (**25 keywords**) and easy tooling.
- Go's **concurrency primitives** make it easy to construct **streaming data pipelines** that make efficient use of I/O and multiple CPUs.
## A word about Pipelines
A **pipeline** is a series of **stages** connected by **channels**, where each stage is a **group of goroutines**
running the **same function**. In each stage, the goroutines:
- **receive** values from upstream via **inbound channels**
- **perform** some function on that data, usually **producing new values**
- **send** values downstream via **outbound channels**
Each stage has any number of inbound and outbound channels, except the first and last stages, which have only outbound
or inbound channels, respectively. The **first stage** is sometimes called the **source or producer**; the **last stage**,
the **sink or consumer**.
## Basic Syntax 1-2
.code -numbers basic_syntax/main.go /START 1/,/END 1/
## Basic Syntax 2-2
.play -numbers basic_syntax/main.go /START 2/,/END 2/
## Functions/Closures
.play -numbers functions/main.go /START 1/,/END 1/
## Defer
.play -numbers defer/main.go /START 1/,/END 1/
## Channels
.play -numbers channels/main.go /START 1/,/END 1/
## Goroutines
.play -numbers goroutines/main.go /START/,/END/
## For-range
.play -numbers for_range/main.go /START/,/END/
## Select
.play -edit -numbers select/main.go /START/,/END/
## Pipelines
We'll start with a simple **string transformation pipeline**, starting with our **producer**:
.code basic_pipeline_1/main.go /START FROMARRAY/,/END FROMARRAY/
.play basic_pipeline_1/main.go /START MAINFROMARRAY/,/END MAINFROMARRAY/
## Pipelines
Next, let's add a **logger** stage to see what's going on:
.code basic_pipeline_2/main.go /START LOGGER/,/END LOGGER/
.play basic_pipeline_2/main.go /START MAINLOGGER1/,/END MAINLOGGER1/
## Pipelines
Next, let's add an **upper** stage:
.code basic_pipeline_3/main.go /START UPPER/,/END UPPER/
.play basic_pipeline_3/main.go /START MAINUPPER/,/END MAINUPPER/
## Pipelines
Add another **logger** stage:
.play basic_pipeline_4/main.go /START MAINLOGGER2/,/END MAINLOGGER2/
## Pipelines
Now, let's add a **quote** stage:
.code basic_pipeline_5/main.go /START QUOTE/,/END QUOTE/
.play basic_pipeline_5/main.go /START MAINQUOTE/,/END MAINQUOTE/
## Pipelines
Finally, we can add another **logger** stage:
.play -edit basic_pipeline_6/main.go /START MAINLOGGER3/,/END MAINLOGGER3/