Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide public MarshalStruct #182

Open
liangxuuu opened this issue Nov 11, 2021 · 3 comments
Open

Provide public MarshalStruct #182

liangxuuu opened this issue Nov 11, 2021 · 3 comments

Comments

@liangxuuu
Copy link

liangxuuu commented Nov 11, 2021

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})
}
@guregu
Copy link
Owner

guregu commented Nov 18, 2021

To clarify: Would MarshalStruct work like MarshalItem but ignore custom marshalers (MarshalDynamoItem)?

@liangxuuu
Copy link
Author

To clarify: Would MarshalStruct work like MarshalItem but ignore custom marshalers (MarshalDynamoItem)?

Yes, I think this will be very useful

@guregu
Copy link
Owner

guregu commented Feb 6, 2022

I don't have support for this yet, but auxiliary types are supported now in the latest version: #181

You can use them as a workaround for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants