-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
315 lines (284 loc) · 8.35 KB
/
main.go
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package main
import (
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"io/ioutil"
"math/rand"
"strconv"
)
var config = aws.NewConfig().WithEndpoint("http://localhost:16666").WithRegion("share-local")
var db = dynamodb.New(config)
var images = make(map[string][]string)
func PrintTableNames() {
listTableParams := &dynamodb.ListTablesInput{}
resp, err := db.ListTables(listTableParams)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp)
}
func ScanImageTable() {
params := &dynamodb.ScanInput{
TableName: aws.String("Image"),
AttributesToGet: []*string{},
}
resp, err := db.Scan(params)
if err != nil {
fmt.Println(err)
return
}
// fmt.Println(resp)
fmt.Println(*resp.Count)
}
func ScanImageTagTable() {
params := &dynamodb.ScanInput{
TableName: aws.String("ImageTag"),
AttributesToGet: []*string{
aws.String("Tag"),
aws.String("ImageId"),
aws.String("VoteCount"),
},
}
resp, err := db.Scan(params)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(*resp.Count)
}
func AddImages() {
for image, _ := range images {
addItemParams := &dynamodb.PutItemInput{
TableName: aws.String("Image"),
Item: map[string]*dynamodb.AttributeValue{
"Id": &dynamodb.AttributeValue{
S: aws.String(image),
},
"DateAdded": &dynamodb.AttributeValue{
S: aws.String("today"),
},
"VoteCount": &dynamodb.AttributeValue{
N: aws.String(strconv.Itoa(rand.Intn(100))),
},
},
}
_, err := db.PutItem(addItemParams)
if err != nil {
fmt.Println(err)
return
}
}
}
func AddImageTags() {
for image, tags := range images {
for _, tag := range tags {
addItemParams := &dynamodb.PutItemInput{
TableName: aws.String("ImageTag"),
Item: map[string]*dynamodb.AttributeValue{
"Tag": &dynamodb.AttributeValue{
S: aws.String(tag),
},
"ImageId": &dynamodb.AttributeValue{
S: aws.String(image),
},
"VoteCount": &dynamodb.AttributeValue{
N: aws.String(strconv.Itoa(rand.Intn(100))),
},
},
}
_, err := db.PutItem(addItemParams)
if err != nil {
fmt.Println(err)
return
}
}
}
}
func QueryImageTagTable() {
params := &dynamodb.QueryInput{
TableName: aws.String("ImageTag"),
KeyConditions: map[string]*dynamodb.Condition{
"Tag": {
ComparisonOperator: aws.String("EQ"),
AttributeValueList: []*dynamodb.AttributeValue{
{
S: aws.String("Application Services"),
},
},
},
},
}
resp, err := db.Query(params)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp)
}
func main() {
images["android.png"] = []string{"SDKs & Tools", "Android"}
images["appstream.png"] = []string{"Application Services", "Amazon AppStream"}
images["cli.png"] = []string{"SDKs & Tools", "AWS CLI"}
images["cloudformation.png"] = []string{"Deployment & Management", "AWS CloudFormation"}
images["cloudfront.png"] = []string{"Storage & CDN", "Amazon CloudFront"}
images["cloudsearch.png"] = []string{"Application Services", "Amazon CloudSearch"}
images["cloudtrail.png"] = []string{"Deployment & Management", "AWS CloudTrail"}
images["cloudwatch.png"] = []string{"Deployment & Management", "Amazon CloudWatch"}
images["data-pipeline.png"] = []string{"Analytics", "AWS Data Pipeline"}
images["direct-connect.png"] = []string{"Compute & Networking", "AWS Direct Connect"}
images["dotnet.png"] = []string{"SDKs & Tools", ".NET"}
images["dynamodb.png"] = []string{"Database", "Amazon DynamoDB"}
images["ec2.png"] = []string{"Compute & Networking", "Amazon EC2"}
images["eclipse.png"] = []string{"SDKs & Tools", "Eclipse"}
images["elasticache.png"] = []string{"Database", "Amazon ElastiCache"}
images["elastic-beanstalk.png"] = []string{"Deployment & Management", "AWS Elastic Beanstalk"}
images["elb.png"] = []string{"Compute & Networking", "Elastic Load Balancing"}
images["emr.png"] = []string{"Analytics", "Amazon EMR"}
images["glacier.png"] = []string{"Storage & CDN", "Amazon Glacier"}
images["iam.png"] = []string{"Deployment & Management", "AWS IAM"}
images["ios.png"] = []string{"SDKs & Tools", "iOS"}
images["java.png"] = []string{"SDKs & Tools", "Java"}
images["kinesis.png"] = []string{"Analytics", "Amazon Kinesis"}
images["nodejs.png"] = []string{"SDKs & Tools", "Node.js"}
images["opsworks.png"] = []string{"Deployment & Management", "AWS OpsWorks"}
images["php.png"] = []string{"SDKs & Tools", "PHP"}
images["powershell.png"] = []string{"SDKs & Tools", "PowerShell"}
images["python.png"] = []string{"SDKs & Tools", "Python"}
images["rds.png"] = []string{"Database", "Amazon RDS"}
images["redshift.png"] = []string{"Database", "Amazon Redshift"}
images["route53.png"] = []string{"Compute & Networking", "Amazon Route 53"}
images["ruby.png"] = []string{"SDKs & Tools", "Ruby"}
images["s3.png"] = []string{"Storage & CDN", "Amazon S3"}
images["ses.png"] = []string{"Application Services", "Amazon SES"}
images["sns.png"] = []string{"Application Services", "Amazon SNS"}
images["sqs.png"] = []string{"Application Services", "Amazon SQS"}
images["storage-gateway.png"] = []string{"Storage & CDN", "Amazon Storage Gateway"}
images["swf.png"] = []string{"Application Services", "Amazon SWF"}
images["transcoding.png"] = []string{"Application Services", "Amazon Elastic Transcoder"}
images["visual-studio.png"] = []string{"SDKs & Tools", "Visual Studio"}
images["vpc.png"] = []string{"Compute & Networking", "Amazon VPC"}
// Print all the table names
PrintTableNames()
// Create the image table
imageJson, err := ioutil.ReadFile("./Image.json")
if err != nil {
fmt.Println(err)
return
}
var imageTableCreateInput dynamodb.CreateTableInput
err = json.Unmarshal(imageJson, &imageTableCreateInput)
if err != nil {
fmt.Println(err)
return
}
_, err = db.CreateTable(&imageTableCreateInput)
if err != nil {
fmt.Println(err)
}
// Create the image tag table
imageTagJson, err := ioutil.ReadFile("./ImageTag.json")
if err != nil {
fmt.Println(err)
return
}
var imageTagTableCreateInput dynamodb.CreateTableInput
err = json.Unmarshal(imageTagJson, &imageTagTableCreateInput)
if err != nil {
fmt.Println(err)
return
}
_, err = db.CreateTable(&imageTagTableCreateInput)
if err != nil {
fmt.Println(err)
}
AddImages()
AddImageTags()
ScanImageTable()
ScanImageTagTable()
QueryImageTagTable()
// Add a row to the table
// addItemParams := &dynamodb.PutItemInput{
// TableName: aws.String("Users"),
// Item: map[string]*dynamodb.AttributeValue{
// "Id": &dynamodb.AttributeValue{
// N: aws.String("1"),
// },
// "FirstName": &dynamodb.AttributeValue{
// S: aws.String("Alex"),
// },
// "LastName": &dynamodb.AttributeValue{
// S: aws.String("Thurston"),
// },
// "Age": &dynamodb.AttributeValue{
// S: aws.String("33"),
// },
// },
// }
// _, err = db.PutItem(addItemParams)
// if err != nil {
// fmt.Println(err)
// return
// }
// Add another row to the table
// addItemParams = &dynamodb.PutItemInput{
// TableName: aws.String("Users"),
// Item: map[string]*dynamodb.AttributeValue{
// "Id": &dynamodb.AttributeValue{
// N: aws.String("2"),
// },
// "FirstName": &dynamodb.AttributeValue{
// S: aws.String("Lauren"),
// },
// "LastName": &dynamodb.AttributeValue{
// S: aws.String("Jolly"),
// },
// "Age": &dynamodb.AttributeValue{
// S: aws.String("33"),
// },
// },
// }
// _, err = db.PutItem(addItemParams)
// if err != nil {
// fmt.Println(err)
// return
// }
// Read a row from the table
// getItemParams := &dynamodb.GetItemInput{
// TableName: aws.String("Users"),
// Key: map[string]*dynamodb.AttributeValue{
// "Id": &dynamodb.AttributeValue{
// N: aws.String("2"),
// },
// },
// AttributesToGet: []*string{
// aws.String("FirstName"),
// aws.String("LastName"),
// aws.String("Age"),
// },
// }
// resp, getErr := db.GetItem(getItemParams)
// if getErr != nil {
// fmt.Println(getErr)
// return
// }
// fmt.Println(resp)
deleteImageTableParams := &dynamodb.DeleteTableInput{
TableName: aws.String("Image"),
}
_, err = db.DeleteTable(deleteImageTableParams)
if err != nil {
fmt.Println(err)
}
deleteImageTagTableParams := &dynamodb.DeleteTableInput{
TableName: aws.String("ImageTag"),
}
_, err = db.DeleteTable(deleteImageTagTableParams)
if err != nil {
fmt.Println(err)
}
PrintTableNames()
fmt.Println("Done")
}