google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.16k stars 362 forks source link

Make uuid.Nil and other values as a constant #120

Closed xorcare closed 8 months ago

xorcare commented 11 months ago

Hello! I suggest to make uuid.Nil and other global uuids as constant to avoid modification at runtime.

One example of a problem I look in practice:

err = rows.Scan(
    &uuid.Nil, // for group by only
    //...
)

Such a seemingly innocuous change modifies the value of the uuid.Nil variable, and breaks the comparison.

var uid uuid.UUID

if uid == uuid.Nil {
    // This condition doesn't work.
}
xorcare commented 8 months ago

Unfortunately there is no way to make a constant from an array, and my suggestion is meaningless. My mistake, sorry. 🥲