mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-18 16:30:44 +00:00
Generate legit ResourceIds for SDK compatibility
This commit is contained in:
34
internal/resourceid/resourceid.go
Normal file
34
internal/resourceid/resourceid.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package resourceid
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func New() string {
|
||||
id := uuid.New().ID()
|
||||
idBytes := uintToBytes(id)
|
||||
|
||||
return base64.StdEncoding.EncodeToString(idBytes)
|
||||
}
|
||||
|
||||
func NewCombined(ids ...string) string {
|
||||
combinedIdBytes := make([]byte, 0)
|
||||
|
||||
for _, id := range ids {
|
||||
idBytes, _ := base64.StdEncoding.DecodeString(id)
|
||||
combinedIdBytes = append(combinedIdBytes, idBytes...)
|
||||
}
|
||||
|
||||
return base64.StdEncoding.EncodeToString(combinedIdBytes)
|
||||
}
|
||||
|
||||
func uintToBytes(id uint32) []byte {
|
||||
buf := make([]byte, 4)
|
||||
for i := 0; i < 4; i++ {
|
||||
buf[i] = byte(id >> (i * 8))
|
||||
}
|
||||
|
||||
return buf
|
||||
}
|
||||
Reference in New Issue
Block a user