doc.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Package dynamodbattribute provides marshaling utilities for marshaling to
  2. // dynamodb.AttributeValue types and unmarshaling to Go value types. These
  3. // utilities allow you to marshal slices, maps, structs, and scalar values
  4. // to and from dynamodb.AttributeValue. These are useful when marshaling
  5. // Go value tyes to dynamodb.AttributeValue for DynamoDB requests, or
  6. // unmarshaling the dynamodb.AttributeValue back into a Go value type.
  7. //
  8. // Marshal Go value types to dynamodb.AttributeValue: See (ExampleMarshal)
  9. //
  10. // type Record struct {
  11. // MyField string
  12. // Letters []string
  13. // A2Num map[string]int
  14. // }
  15. //
  16. // ...
  17. //
  18. // r := Record{
  19. // MyField: "dynamodbattribute.Marshal example",
  20. // Letters: []string{"a", "b", "c", "d"},
  21. // A2Num: map[string]int{"a": 1, "b": 2, "c": 3},
  22. // }
  23. // av, err := dynamodbattribute.Marshal(r)
  24. // fmt.Println(av, err)
  25. //
  26. // Unmarshal dynamodb.AttributeValue to Go value type: See (ExampleUnmarshal)
  27. //
  28. // r2 := Record{}
  29. // err = dynamodbattribute.Unmarshal(av, &r2)
  30. // fmt.Println(err, reflect.DeepEqual(r, r2))
  31. //
  32. // Marshal Go value type for DynamoDB.PutItem:
  33. //
  34. // sess, err := session.NewSession()
  35. // if err != nil {
  36. // fmt.Println("Failed create session", err)
  37. // return
  38. // }
  39. //
  40. // svc := dynamodb.New(sess)
  41. // item, err := dynamodbattribute.MarshalMap(r)
  42. // if err != nil {
  43. // fmt.Println("Failed to convert", err)
  44. // return
  45. // }
  46. // result, err := svc.PutItem(&dynamodb.PutItemInput{
  47. // Item: item,
  48. // TableName: aws.String("exampleTable"),
  49. // })
  50. //
  51. //
  52. //
  53. // The ConvertTo, ConvertToList, ConvertToMap, ConvertFrom, ConvertFromMap
  54. // and ConvertFromList methods have been deprecated. The Marshal and Unmarshal
  55. // functions should be used instead. The ConvertTo|From marshallers do not
  56. // support BinarySet, NumberSet, nor StringSets, and will incorrect marshal
  57. // binary data fields in structs as base64 strings.
  58. //
  59. // The Marshal and Unmarshal functions correct this behavior, and removes
  60. // the reliance on encoding.json. `json` struct tags are still supported. In
  61. // addition support for a new struct tag `dynamodbav` was added. Support for
  62. // the json.Marshaler and json.Unmarshaler interfaces have been removed and
  63. // replaced with have been replaced with dynamodbattribute.Marshaler and
  64. // dynamodbattribute.Unmarshaler interfaces.
  65. //
  66. // `time.Time` is marshaled as RFC3339 format.
  67. package dynamodbattribute