emahiro/b.log

Drastically Repeat Yourself !!!!

dynamodbattribute には omitempty が使える

ただの備忘録です。

dynamodbattribute には omitemtpty タグが使えてStruct の中でゼロ値になってしまうところを無視したい(Item の attribute として登録したくない)ケースにおいては使えるなと思いました。

https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/dynamodbattribute/#Marshal

The omitempty tag is only used during Marshaling and is ignored for Unmarshal. Any zero value or a value when marshaled results in a AttributeValue NULL will be added to AttributeValue Maps during struct marshal. The omitemptyelem tag works the same as omitempty except it applies to maps and slices instead of struct fields, and will not be included in the marshaled AttributeValue Map, List, or Set.