This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolang-intro.slide
203 lines (121 loc) · 4.29 KB
/
golang-intro.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
The Go Programming Language
An Introduction
14:30 01 Feb 2017
Tags: go golang
Stefan Scheidt
Software Engineer, REWE digital
https://rewe-digital.com/
@stefanscheidt
* The Go Programming Language
"Go is an open source programming language that makes it easy to build simple, reliable, and efficient software."
.link http://golang.org
.image assets/gopher.png
.link https://blog.golang.org/gopher The Go Gopher
* Language Origin
- created at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson
- officially announced in November 2009
- Go 1.0 released in March 2012
- with specification of the language and libraries
- current release: 1.7.5
.link https://en.wikipedia.org/wiki/Go_(programming_language) Wikipedia
.link https://golang.org/ref/spec Language specification
.link https://golang.org/doc/faq#Origins golang FAQ
* Why a new language?
Motivated by needs at Google:
- Efficiency
- Safety
- Concurrency
- Scalability
- Fast development cycle
- No surprises
.link https://talks.golang.org/2012/simple.slide#4 "Go: a simple programming environment", Andrew Gerrand
* Why Go at REWE digital?
Many infrastructure tools we use are written in Go
- Consul
- Docker
- Kubernetes
- Prometheus
- ...
.link https://github.com/golang/go/wiki/Projects
Fits well for microservice development
* Language Fact Sheet
- Deliberately simple C style language design
- statically typed, compiled (fast, cross, small binary)
- a toolchain that, by default, produces statically linked native binaries without external dependencies
- limited structural typing
- no inheritance, but embedding
- no generics
- memory safety, garbage collection
- build-in concurrency (go routines)
- CSP-style concurrent programming (message passing via channels)
- comprehensive standard library
* Hello, World!
.play helloworld/main.go
* Basic Types
`bool`
`string`
`int`, `int8`, `int16`, `int32`, `int64`
`uint`, `uint8`, `uint16`, `uint32`, `uint64`, `uintptr`
`byte` (alias for `uint8`)
`rune` (alias for `int32`, represents a Unicode code point)
`float32` `float64`
`complex64` `complex128`
* Pointers
.play -edit pointers/main.go
* Functions
.play -edit functions/main.go
* Structs
.play -edit structs/main.go
* Methods
.play -edit methods/main.go /START OMIT/,/END OMIT/
* Interfaces (1)
.play -edit interfaces1/main.go /START OMIT/,/END OMIT/
* Interfaces (2)
.code interfaces2/stringer.txt
.play -edit interfaces2/main.go /START OMIT/,/END OMIT/
* Error Handling
.code errors/ioutil.txt
.play -edit errors/main.go /START OMIT/,/END OMIT/
* Go Routines
.play -edit goroutines/main.go /START OMIT/,/END OMIT/
* Channels (1)
.play -edit channels/main.go /START OMIT/,/END OMIT/
* Channels (2)
.code multiplexing/main.go /START say OMIT/,/END say OMIT/
* Channels (3)
.code multiplexing/main.go /START fanIn OMIT/,/END fanIn OMIT/
* Channels (4)
.play -edit multiplexing/main.go /START main OMIT/,/END main OMIT/
* Packages
- Go code lives in packages.
- Packages contain constant, type, function and variable declarations.
- Packages can be very small (package errors has just one declaration) or very large (package net/http has >100 declarations). Most are somewhere in between.
- Case determines visibility: Foo is exported, foo is not.
* Go Standard Library
.link https://golang.org/pkg/
e.g.
- encoding/decoding of various formats
- data-driven templates for generating text and HTML output
- HTTP client and server implementations
* Sample Application
.link https://github.com/stefanscheidt/weatherservice-go Simple Weather Service
* GOPATH and Imports
The GOPATH environment variable lists places to look for Go code.
If DIR is a directory listed in the GOPATH, a package with source in DIR/src/foo/bar can be imported as "foo/bar".
The command "go get" downloads, compiles and installs the packages named by the import paths, along with their dependencies, e.g.
go get github.com/user/project
.link https://godoc.org/
* Go Package Management
.image assets/picard-facepalm.gif
* Go Tools
Usage:
go command [arguments]
Commands:
.code gocommands/commands.txt
* Learn Go
.link https://tour.golang.org
.link https://play.golang.org
* Slides
.link http://go-talks.appspot.com/github.com/rewe-digital/golang-intro/golang-intro.slide
.link https://github.com/rewe-digital/golang-intro