[MM-44925] simplified the ID generator (#20398)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
485f44c136
Коммит
ef3f1b5796
@@ -4,7 +4,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
@@ -268,18 +267,13 @@ func NewAppError(where string, id string, params map[string]interface{}, details
|
|||||||
return ap
|
return ap
|
||||||
}
|
}
|
||||||
|
|
||||||
var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769")
|
var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769").WithPadding(base32.NoPadding)
|
||||||
|
|
||||||
// NewId is a globally unique identifier. It is a [A-Z0-9] string 26
|
// NewId is a globally unique identifier. It is a [A-Z0-9] string 26
|
||||||
// characters long. It is a UUID version 4 Guid that is zbased32 encoded
|
// characters long. It is a UUID version 4 Guid that is zbased32 encoded
|
||||||
// with the padding stripped off.
|
// without the padding.
|
||||||
func NewId() string {
|
func NewId() string {
|
||||||
var b bytes.Buffer
|
return encoding.EncodeToString(uuid.NewRandom())
|
||||||
encoder := base32.NewEncoder(encoding, &b)
|
|
||||||
encoder.Write(uuid.NewRandom())
|
|
||||||
encoder.Close()
|
|
||||||
b.Truncate(26) // removes the '==' padding
|
|
||||||
return b.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRandomTeamName is a NewId that will be a valid team name.
|
// NewRandomTeamName is a NewId that will be a valid team name.
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user