dynamo
dynamo copied to clipboard
Provide public MarshalStruct
Can we provide a public function MarshalStruct
for external calls, in case the caller just needs to add some extra fields to the marshal process but doesn't want to actually handle the marshal process himself?
For example:
// dynamodb table
type Item struct {
PK string `dynamo:",hash"`
}
type User struct {
Username string
Email string
}
type UserItem struct {
*Item
*User
}
// We want to add PK automatically in the marshal process
func (u *User) MarshalDynamoItem() (map[string]*dynamodb.AttributeValue, error) {
return dynamo.MarshalStruct(&UserItem{&Item{PK:"U#"+u.Username}, u})
}
To clarify: Would MarshalStruct
work like MarshalItem
but ignore custom marshalers (MarshalDynamoItem
)?
To clarify: Would
MarshalStruct
work likeMarshalItem
but ignore custom marshalers (MarshalDynamoItem
)?
Yes, I think this will be very useful
I don't have support for this yet, but auxiliary types are supported now in the latest version: https://github.com/guregu/dynamo/issues/181
You can use them as a workaround for this issue.