Пример #1
0
func Example_marshaling(client *dynago.Client) {
	type MyStruct struct {
		Id          int64
		Name        string
		Description string
		Tags        []string
		Address     struct {
			City  string
			State string
		}
	}

	var data MyStruct

	doc := dynago.Document{
		// Basic fields like numbers and strings get marshaled automatically
		"Id":          data.Id,
		"Name":        data.Name,
		"Description": data.Description,
		// StringSet is compatible with []string so we can simply cast it
		"Tags": dynago.StringSet(data.Tags),
		// We don't automatically marshal structs, nest it in a document
		"Address": dynago.Document{
			"City":  data.Address.City,
			"State": data.Address.State,
		},
	}

	client.PutItem("Table", doc).Execute()
}
Пример #2
0
func ExampleClient_PutItem(client *dynago.Client) {
	doc := dynago.Document{
		"Id":   42,
		"Name": "Bob",
		"Address": dynago.Document{
			"City":  "Boston",
			"State": "MA",
		},
	}
	_, err := client.PutItem("Person", doc).Execute()
	if err != nil {
		fmt.Printf("PUT failed: %v", err)
	}
}