-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbapi_rig.go
45 lines (40 loc) · 980 Bytes
/
dbapi_rig.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
package main
import (
"errors"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)
func addRig(db dynamodb.DynamoDB) error {
hasBool, err := hasItem(db, *flagTable, *flagAdd, *flagCreateDate)
if err != nil {
return err
}
if hasBool {
return errors.New("The data already exists. Can not add data")
}
item := Rig{
Typ: *flagAdd,
CreateDate: *flagCreateDate,
Product: *flagProduct,
ProductStatus: *flagProductStatus,
ProductUser: *flagUser,
MonetaryUnit: *flagMonetaryUnit,
Cost: *flagCost,
PurchaseDate: *flagPurchaseDate,
Description: *flagDescription,
}
dynamodbJSON, err := dynamodbattribute.MarshalMap(item)
if err != nil {
return err
}
data := &dynamodb.PutItemInput{
Item: dynamodbJSON,
TableName: aws.String(*flagTable),
}
_, err = db.PutItem(data)
if err != nil {
return err
}
return nil
}