Skip to content

Commit

Permalink
Merge pull request #118 from zeropsio/go-update
Browse files Browse the repository at this point in the history
Go update
  • Loading branch information
jansaidl authored Mar 7, 2024
2 parents 75753dd + 6ce1857 commit c43b79d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/uuid/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ package uuid

import (
"encoding/base64"
"strings"

"github.com/google/uuid"
)

const encodeUUID = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB"

var encoding = base64.NewEncoding(encodeUUID)

func GetShort() string {
x := uuid.New()
return encoding.EncodeToString(x[:])[0:22]
return encode(x[:])
}

func encode(uuid []byte) string {
b64 := base64.RawURLEncoding.EncodeToString(uuid)
// TODO(tikinang): Fix for 1.22, improve.
b64 = strings.ReplaceAll(b64, "-", "A")
b64 = strings.ReplaceAll(b64, "_", "B")
// Should already be 22 chars, just making sure if creators of base64 package change their mind.
return b64[:22]
}

0 comments on commit c43b79d

Please sign in to comment.