f510ac994c
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
40 lines
767 B
Go
40 lines
767 B
Go
package rnd
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// PPID returns a unique id with prefix as string.
|
|
func PPID(prefix byte) string {
|
|
result := make([]byte, 0, 16)
|
|
result = append(result, prefix)
|
|
result = append(result, strconv.FormatInt(time.Now().UTC().Unix(), 36)[0:6]...)
|
|
result = append(result, Token(9)...)
|
|
|
|
return string(result)
|
|
}
|
|
|
|
// IsPPID returns true if string is a unique id as generated by PhotoPrism.
|
|
func IsPPID(s string, prefix byte) bool {
|
|
if len(s) != 16 {
|
|
return false
|
|
}
|
|
|
|
return s[0] == prefix
|
|
}
|
|
|
|
// IsUID returns true if string is a seemingly unique id.
|
|
func IsUID(s string, prefix byte) bool {
|
|
// Regular UUID.
|
|
if len(s) == 36 {
|
|
return true
|
|
}
|
|
|
|
// Not a known UID format.
|
|
if len(s) != 16 {
|
|
return false
|
|
}
|
|
|
|
return IsPPID(s, prefix)
|
|
}
|