英文:
aws-sdk-go-v2 attributevalue.Marshaler interface not working
问题
我尝试实现aws-sdk-go-v2的attributevalue.Marshaler接口,但没有效果。始终在数据库中存储一个空对象。
我有以下结构体:
type ID struct {
value string
}
我尝试了两个版本的marshaler:
func (id *ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberM{
Value: map[string]types.AttributeValue{
"value": &types.AttributeValueMemberS{Value: id.value},
},
}, nil
}
和
func (id *ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberS{Value: id.value}, nil
}
在这两种情况下,我可以通过调试器看到它进入了函数,并且返回的值看起来是正确的。但是在检查数据库后,id被存储为一个没有属性的对象。
英文:
I try to implement the aws-sdk-go-v2 attributevalue.Marshaler interface but it has no effect. An empty object is always stored on the db.
I have the following struct
type ID struct {
value string
}
it tried both versions of the marshaler
func (id *ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberM{
Value: map[string]types.AttributeValue{
"value": &types.AttributeValueMemberS{Value: id.value},
},
}, nil
}
and
func (id *ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberS{Value: id.value}, nil
}
in both cases I can see with the debugger that it enters on the function and looks likes the returned value is correct. But after that when I check on the db the id is stored as an object without properties.
答案1
得分: 1
问题是 ID 上的链接无法工作:
这个不会工作:
func (id *ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberS{Value: id.value}, nil
}
但是去掉链接的相同代码可以工作:
func (id ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberS{Value: id.value}, nil
}
英文:
The problem is the link on the ID
that will not work:
func (id *ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberS{Value: id.value}, nil
}
but the same thing without link works
func (id ID) MarshalDynamoDBAttributeValue() (types.AttributeValue, error) {
return &types.AttributeValueMemberS{Value: id.value}, nil
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论