forked from tkmagesh/IBM-AdvGo-Mar-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
163 lines (120 loc) · 4.06 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
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
Magesh Kuppan
Schedule:
Commence : 9:30 AM
Tea Break : 11:00 AM (20 mins)
Lunch Break : 1:00 PM (1 hr)
Tea Break : 3:30 PM (20 mins)
Wind up : 5:30 PM
Methodoly:
No powerpoints
100% Hands on
Atleast 50% of the participants should have completed the assignments
About You:
Name
Experience
Primary Skillset
Experience in Go
Any intesting books / shows you read / watched
interfaces
functional programming
concurrency
interfaces
implementation is 'implicit'
Higher Order functions
Functions that can be treated like 'data'
Functions can be assigned to variables
Functions can be passed as arguments to other functions
Functions can be returned as return values by other functions
Concurrency
Golang is built FOR concurrency
go, select, range, chan (data type), <- (channel operator)
DO NOT ASSUME:
1. the time taken for a goroutine to complete
2. the order in which goroutines invoked / complete
To detect race conditions
go run --race demo-06.go
go build --race demo-06.go
channel
//create
ch := make(chan int)
//send data
ch <- 100
//receive data
<- ch
Receive operation is ALWAYS a blocking operation
Send operation is blocked until a Receive operation is initiated
Assignment-01:
modify demo-20.go to generate the prime numbers until the user hits ENTER key
NOTE: do NOT capture the ENTER key from the genPrimes function
Resource Pooling
Create a pool with a size & factory
Acquire Resource from the pool
if there are resources in the pool
return from the pool
else
use the factory to create the resource and return it
Release Resource to the pool
if the pool is full
discard the resource
else
add the resource to the pool
IMPORTANT:
1. the factory should be thread-safe
2. the pool should be thread-safe
3. When a resource is acquired, it should not be allowed to be acquired again until it is released
GRPC
http2
Communication Patterns
Request & Response
Server Streaming (One Request & Stream of Responses)
Client Streaming (Stream of Requests & One Response)
Bidirection Streaming (Stream of Requests & Stream of Responses)
Create a .proto file with the following contracts
Service contract
Operation Contract
Message Contract
ON the service side
Create a Stub using the .proto file
Implement the service
Host the service
On the client side
Create a proxy using the .proto file
Us the proxy to Call the service
Installation
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
(when the above is installed, executables are created in the gopath/bin folder. Make sure this path is set in environment variables)
Windows
Install the binaries from https://github.com/protocolbuffers/protobuf/releases/
Mac
brew install protoc-gen-go
brew install protoc-gen-go-grpc
To generate the proxy and stub
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/service.proto
HTTP Services
Only using the platform APIS
How to handle errors?
How to serialize / deserialze data?
How to log the request and response?
Routing Libraries
router.GET("/", func(){
})
Web Frameworks
Gin
Microservice
go-kit
HTML5 (Browser as an OS)
Persist data on the client side
Local Storage
Session Storage
IndexedDB
Make the application available offline
Offline Application Cache
Service Worker
Real time updates from the server
Server Sent Events
Web Sockets
Multithreading
Web Workers
Web Socket
gorilla/websocket