Fixed authentication key generation for partition key ranges

Fixed collection rid generation

Improved compatibility with SDKs
This commit is contained in:
Pijus Kamandulis
2024-06-01 02:10:20 +03:00
parent ec5f82cd54
commit 0cec7816c1
12 changed files with 38 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package resourceid
import (
"encoding/base64"
"math/rand"
"github.com/google/uuid"
)
@@ -10,6 +11,12 @@ func New() string {
id := uuid.New().ID()
idBytes := uintToBytes(id)
// first byte should be bigger than 0x80 for collection ids
// clients classify this id as "user" otherwise
if (idBytes[0] & 0x80) <= 0 {
idBytes[0] = byte(rand.Intn(0x80) + 0x80)
}
return base64.StdEncoding.EncodeToString(idBytes)
}