I would like to get ObjectID as a string because I have other storage types, so I want to avoid to use primitive.ObjectID in my struct to keep the layers independent. I'm new to Golang, thanks.
package listing
type Card struct {
ID string
Hanzi string
Pinyin string
Traducao string
}
My storage file: package storage
func (m *Mongodb)GetCards() []*listing.Card {
var list []*listing.Card
collection := m.Client.Database("flashcards").Collection("cards")
cur, err := collection.Find(context.TODO(), bson.M{})
if err != nil {
log.Fatal("Erro buscando cards:", err)
}
for cur.Next(context.TODO()) {
var card listing.Card
err = cur.Decode(&card)
if err != nil {
log.Fatal("Erro decodificando documento", err)
}
list = append(list, &card)
}
return list
}