-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGo Fundamental Notes
More file actions
95 lines (62 loc) · 2.01 KB
/
Go Fundamental Notes
File metadata and controls
95 lines (62 loc) · 2.01 KB
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
GO COMMANDS
go version = Prints go version
go run [filename] = compile and run a go file
go build [filename] = compile packages and dependencies (creates an executable file)
- the .go extension must be included in the filename
Variables store information to be used later
Instead of typing the same thing over again you can store it in a variable and use the variable name in it's place
Package Scope Variable
var [name] [type](int, float, string..)
Short Declaration:
[name] := [value]
- Can only be used within a code block inside a function.
- Type is figured out automatically
// means a comment.
- Comments are ignored.
Signature of a Function:
func (receiver) identifier(parameters) (returns){
code block
}
- receiver and returns are optional
- parameters can be blank
- when calling a function the parenthesis are required. "func()"
Strings:
- Whatever is in a string will show up exactly how it is typed
- strings are denoted by "" or ''
- '' is a raw string literal
Concatenation is using the + operator to combine things
String Concatenation:
- ("Hello," + argument + "!")
DATA STRUCTURES
SLICE = keep a list of values of the same type
[][type]{[values]}
- []string{"","",""}
- Access by index position
- The first value in an Index is 0, not 1 like people are used to starting at. (0 based)
- 0 based index
[name][index #]
MAP = Stores key, value pairs
map[key type][value type]{}
map[string]int{"string" : int, "string" : int, "string" : int}
- Always comes out in a random order
- Accessed by key
- Cannot have Duplicate Entries
[name][key]
LOOPS
FOR LOOP:
for [iterator], [iterator][Relational Operator][Limit], [incrementor]{
//code
}
- will run the code inside the code block until the iterator meets its' limit
- for i := 0; i < 100; i++{
}
- i++ = i + 1
for [iterator], [value] := range [variable]
- for i, v := range m {
//code
}
- i = iterator
- v = value
- i or v can be left blank by using '_'
VALUABLE FUNCTIONS
len(arg) = Tells you the length of something