-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read me
192 lines (156 loc) · 4.6 KB
/
Read me
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
// This program implements a Covid lookup service
// over TCP or Unix Data Socket. It loads CSV Covid Dataset
// information using package lib (see above) and uses a simple
// text-based protocol to interact with the client and send
// the data.
//
// Clients send covid dataset search requests as a textual command in the form:
// Open new Terminal:
// $ go run serertxt.go
// Open another Terminal:
// $ nc localhost 4040
// $ {"query": {"region": "Sindh"}}
// $ {"query": {"date": "4/4/2020"}}
// for query It's mendatory to follow the given JSOn Structure as it is given above.
//
// When the server receives the request, it is parsed and is then used
// to search the list of covid Dataset. The search result is then printed
// JSON Format dataset to the client.
//
// Focus:
// This version of the server uses TCP sockets (or UDS) to implement a simple
// text-based application-level protocol. There are no streaming strategy
// employed for the read/write operations. Buffers are read in one shot
// creating opportunities for missing data during read.
//
// Testing:
// Netcat or telnet can be used to test this server by connecting and
// sending command using the format described above.
//
// Usage: server [options]
// options:
// -e host endpoint, default ":4040"
// -n network protocol [tcp,unix], default "tcp"
Here is complete overview of this tcp server
(Golang): This tasks is designed to help you work with concepts frequently used in backend systems development.
## Programming Language
[Go v1.14](https://golang.org/)
## Task
Write a **TCP Server** that loads dataset from a **CSV file** and provide interface to query the dataset. TCP server will expose port **4040**.
### Dataset
You will be required to download **Corona Virus Pakistan Dataset 2020** from the **OpenData.com.pk**, convert the dataset into a CSV file and use this file to load data into the server.
- Download `COVID_FINAL_DATA.xlsx` from [OpenData.com.pk](https://opendata.com.pk/dataset/corona-virus-pakistan-dataset-2020)
- Convert first sheet "TimeSeries_KeyIndicators" into a CSV file
- Place the CSV file into the repository
Following columns are required in CSV:
- Cumulative Test Positive
- Cumulative Tests Performed
- Date
- Discharged
- Expired
- Admitted
- Region
### Server Communication
User should be able to connect to the server using **NetCat** `nc localhost 4040` command on Linux/Unix based systems.
Once connected to TCP, user should be able communicate with the application by sending queries in JSON format.
```
{
"query": {
"region": "Sindh"
}
}
```
```
{
"query": {
"date": "20/3/2020"
}
}
```
User can query data based on two fields: Region and Date.
In response, server will return a **list** of records that will match query. An individual record's JSON format will look like:
```
{
"date": "2020-03-11",
"positive": 2,
"tests": 171,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
}
```
## Query Examples
```
> nc localhost 4040
> {"query": {"region": "Sindh"}}
> {"response": [
{
"date": "11/03/2020",
"positive": 2,
"tests": 171,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
},
{
"date": "12/3/2020",
"positive": 14,
"tests": 324,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
},
{
"date": "2020-03-13",
"positive": 43,
"tests": 324,
"expired": 0,
"admitted": 12,
"discharged": 0,
"region": "Sindh"
}
]}
```
```
> nc localhost 4040
> {"query": {"date": "2020-03-20"}}
> {"response": [
{
"date": "2020-03-20",
"positive": 2,
"tests": 171,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
},
{
"date": "2020-03-20",
"positive": 14,
"tests": 324,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Punjab"
},
{
"date": "2020-03-20",
"positive": 43,
"tests": 324,
"expired": 0,
"admitted": 12,
"discharged": 0,
"region": "KP"
}
]}
```
## Learning Resources
[Effective Go](https://golang.org/doc/effective_go.html)
[Reading a simple CSV in Go](https://medium.com/@ankurraina/reading-a-simple-csv-in-go-36d7a269cecd)
[Read a CSV File into a Struct](https://golangcode.com/how-to-read-a-csv-file-into-a-struct/)
[Go by Example: JSON](https://gobyexample.com/json)
[Network Programming with Go: A TCP Server with a Custom Protocol](https://www.youtube.com/watch?v=yW1ltZidh7g)
[How to Use Netcat Commands: Examples and Cheat Sheets](https://www.varonis.com/blog/netcat-commands/)