()
| 81 | } |
| 82 | |
| 83 | func main() { |
| 84 | // snippet-start:[dynamodb.go.add_items.args] |
| 85 | jsonFile := flag.String("j", "", "The JSON file containing the items to add to the table") |
| 86 | table := flag.String("d", "", "The name of the database table") |
| 87 | flag.Parse() |
| 88 | |
| 89 | if *jsonFile == "" || *table == "" { |
| 90 | fmt.Println("You must supply a JSON file name and database table name") |
| 91 | fmt.Println("-j JSON-FILE -d TABLE") |
| 92 | return |
| 93 | } |
| 94 | // snippet-end:[dynamodb.go.add_items.args] |
| 95 | |
| 96 | // snippet-start:[dynamodb.go.add_items.session] |
| 97 | sess := session.Must(session.NewSessionWithOptions(session.Options{ |
| 98 | SharedConfigState: session.SharedConfigEnable, |
| 99 | })) |
| 100 | |
| 101 | svc := dynamodb.New(sess) |
| 102 | // snippet-end:[dynamodb.go.add_items.session] |
| 103 | |
| 104 | // snippet-start:[dynamodb.go.add_items.get_items] |
| 105 | items, err := GetItems(jsonFile) |
| 106 | if err != nil { |
| 107 | fmt.Println("Got an error retrieving items:") |
| 108 | fmt.Println(err) |
| 109 | return |
| 110 | } |
| 111 | |
| 112 | for _, item := range items { |
| 113 | av, err := dynamodbattribute.MarshalMap(item) |
| 114 | if err != nil { |
| 115 | fmt.Println("Got error marshalling map:") |
| 116 | fmt.Println(err) |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | err = AddTableItem(svc, av, table) |
| 121 | if err != nil { |
| 122 | fmt.Println("Got an error adding item to table:") |
| 123 | fmt.Println(err) |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | title, err := GetMovieName(av) |
| 128 | if err != nil { |
| 129 | fmt.Println("Got an error retrieving movie name:") |
| 130 | fmt.Println(err) |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | fmt.Println("Successfully added '" + title + " to table " + *table) |
| 135 | } |
| 136 | // snippet-end:[dynamodb.go.add_items.get_items] |
| 137 | } |
| 138 | // snippet-end:[dynamodb.go.add_items] |
nothing calls this directly
no test coverage detected