'unkeyed fields' warning by go-vet

125 views
Skip to first unread message

Denis Shershunov

unread,
May 3, 2019, 11:26:33 AM5/3/19
to mongodb-go-driver
Hello, I'm using go-vet, and every bson.D{{myKey, myValue}} declaration comes with a warning:

go.mongodb.org/mongo-driver/bson/primitive.E composite literal uses unkeyed fields


This is because proper declaration should be bson.D{{Key: myKey, Value: myValue}}, question is, what should I choose as a proper tactic to get rid of all of these warnings ?

1) Do not use literals, create a helper function that would be making proper declaration every time
2) use keyed literals
3) Ignore this for a time being, hoping that this warning will be gone

Wan Bachtiar

unread,
May 28, 2019, 11:34:34 PM5/28/19
to mongodb-go-driver

what should I choose as a proper tactic to get rid of all of these warnings ?

Hi Denis,

If you would like the code to be defined and stronger typed, then it would make sense to define Key and Value. Alternatively you can specify -composites=false to ignore the warning. However, if you decided to ignore, this would be not just for bson.D usages. 

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages