I'm storing attachment in mongodb as Attachment object:
type Attachment struct {
ID string `bson:"_id" json:"id"`
Name string `bson:"name" json:"name"`
URL string `bson:"url" json:"url"`
}
The URL stored is the presigned URL for PUT request, retrieved using AWS session. In Ruby on Rails, I can use virtual attribute to change the URL to presigned URL for GET request:
// models/attachment.rb
def url
if super.present?
// get the presigned URL for get request using the URL from super
else
super
end
end
How can I accomplish this in Go? I have my configs in config.yaml and need to convert yaml to struct. Meanwhile, marshal and unmarshal of BSON only receive data []byte as parameter. I'm not sure how to initiate the AWS session in the marshal and unmarshal of BSON.
I prefer to modify the URL after I query from mongodb, but I want to do it in 1 place