forked from RedHatOfficial/GoCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesson1.slide
135 lines (107 loc) · 3.36 KB
/
lesson1.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
Introduction, Syntax, Formatting, Packages, Types
Lesson 1
20 May 2019
Tags: golang, go
Stanislav Kozina <[email protected]>
Jakub Čajka <[email protected]>
Red Hat, Inc.
https://github.com/RedHatOfficial/GoCourse
* Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/fiveyears.jpg
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/fiveyears.jpg _ 900
* Introduction
- Launched in November 2009 by Google
- Rob Pike, Ken Thompson, Robert Griesemer
- More readable replacement for C/C++/Java/...
- statically typed, compiled, garbage collected
- built-in concurrency
- server-side web (PHP, Node.js, Python)
- cloud technologies (docker, kubernetes)
* Resources
- Tour of Go [[https://tour.golang.org/welcome/1]]
- Effective Go [[https://golang.org/doc/effective_go.html]]
- Go Doc [[https://godoc.org/]]
* Development interface
- Vim;-)
- Visual Studio Code + go lang support [[https://code.visualstudio.com/docs/setup/linux]]
* Packages and Imports
- Program building blocks ("libraries")
- Imported by other programs
- Package name is the last element of the import path
- Standard packages: [[https://golang.org/pkg/]]
.code lesson1/packages.go
* Hello world
.play lesson1/hello.go
.code lesson1/run_hello.go
.code lesson1/build_hello.go
* Packages
- special package main: main() for executables
- Workspace defined by $GOPATH
- Structure for libraries, binaries: src, bin
* go-fmt
.play lesson1/gofmt1.go
.code lesson1/gofmt.go
.play lesson1/gofmt2.go
* Syntax
- Evolved from C
- Declarations in postfix
- Exported symbols begin with Capital letter
- [[https://blog.golang.org/gos-declaration-syntax]]
.code lesson1/syntax_c.go
.code lesson1/syntax_go.go
* Functions
.play lesson1/functions.go
* Multiple return values
.play lesson1/functions2.go
* Named return values
.play lesson1/functions3.go
* Variables
.play lesson1/vars.go
* Types
- Similar to C
- No auto casts
- Type inference && default types
- Each type has clear zero value (0, false, "")
.code lesson1/types.go
* Type conversions
- No auto casts
.play lesson1/casts.go
* Constants
.play lesson1/const.go
* Loops
- Just for loop which also serves as while loop
.play lesson1/for.go
* Conditions
- Similarly to for loop allows init statement
- Variables declared there don't exist outside of the if block
.play lesson1/if.go
* Else statement
- Variables declared in the init statement do exist in the else block
.play lesson1/if2.go
* Switch statement
- Again allows init statement
- Like set of if-else statements
- Evaluated top-bottom, first successful case is executed
- Thus there's no break statement
.play lesson1/switch.go
* Switch statement 2
- Allows non-constant and non-integer values
.play lesson1/switch2.go
* Switch with no condition
- switch without condition is like switch true
.play lesson1/switch3.go
* Error handling
- error is built-in type
[[https://blog.golang.org/error-handling-and-go]]
.play lesson1/ret.go
* Ignoring return values
- '_' idiom can be used to drop return values
.play lesson1/ret2.go
#last slide
* More Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/bumper.png
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/bumper.png _ 900