-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
71 lines (48 loc) · 1.68 KB
/
notes.txt
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
1. Statically Typed (Type must be defined at compile time)
2. Strong Typed (Type of a var cannot change)
3. GO is compiled
4. Fast compile time (Code -> Binary)
5. Built in concurrency (Goroutine)
6. Simple (Garbage Collection)
packages - Folder with go files
modules - Collection of packages
Commands:
cd tutorials
go mod init tutorials
go build -o main main.go
./main
go run main.go (Compile and Run) - No exe generated (To just run this file)
go run *.go -> To run all the files
array - fixed length, same type, indexable, contiguous in memory
slice - array + additional funtionality - more general, powerful and convenient interface
// initiallizing slice with initial capacity has better performance
strings
- array of utf-8 encoded bytes
- immutable
utf-8 encoding = strings in go
ascii = 7 bits = 128 chars
utf-32 = 32 bits = lots of unused bits
utf-8 = variable length encoding
ascii = 1 byte = 0xxx...
é = 233 unicode point number = 2 bytes = 11000011 10101001
struct - user-defined type, define methods that link with struct
anonymous struct - define and initialize, not reuseable
interface - general template for any object
pointers - store memory location
pass by value; pass by reference
goroutines
- Launch multiple functions and run them concurrently
- concurrency != parallel execution
- concurrency = multiple tasks in-progress at the same time
- if multi-core CPU -> parallel execution
channels
- enables goroutine to pass around infomation
- hold data (int, slice, etc)
- thread safe (avoid race condtion during r&w)
- listen for data
- unbuffered channel and buffered channel (store multiple values)
- select stmt = if stmt for channels
---
http
go mod init http
go run main.go