improve direct string warning

This commit is contained in:
rasmus 2022-11-08 08:57:39 +02:00
parent c52c9aa9d9
commit bd667c0fc1

View File

@ -43,6 +43,9 @@ const (
mLogKeyHostId = mLogKeyHostInfo + "." + mLogKeyId mLogKeyHostId = mLogKeyHostInfo + "." + mLogKeyId
) )
// Don't use direct strings in bson types. Use the constants as keys.
// This ensures keys (and subkeys) are consistent, at least within the package.
const ( const (
mLogKeyHostInfo = "host_info" mLogKeyHostInfo = "host_info"
mLogKeyId = "id" mLogKeyId = "id"
@ -59,7 +62,6 @@ const (
// not using marshal, since it is <0.1x performance // not using marshal, since it is <0.1x performance
func (l *mLog) toBson() bson.M { func (l *mLog) toBson() bson.M {
// DO NOT USE QUOTED STRINGS! Move them to const and use variable instead
return bson.M{ return bson.M{
mLogKeyHostInfo: bson.M{ mLogKeyHostInfo: bson.M{
mLogKeyId: l.HostInfo.Id, mLogKeyId: l.HostInfo.Id,