29 lines
677 B
Go
29 lines
677 B
Go
package profile
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.k6n.net/mats/platform/uid"
|
|
)
|
|
|
|
// ProfileId is a 64-bit profile identifier with a compact base62 string form.
|
|
type ProfileId uid.ID
|
|
|
|
// String returns the canonical base62 encoding.
|
|
func (id ProfileId) String() string { return uid.ID(id).String() }
|
|
|
|
// NewProfileId generates a cryptographically random non-zero id.
|
|
func NewProfileId() (ProfileId, error) {
|
|
id, err := uid.New()
|
|
if err != nil {
|
|
return 0, fmt.Errorf("NewProfileId: %w", err)
|
|
}
|
|
return ProfileId(id), nil
|
|
}
|
|
|
|
// ParseProfileId parses a base62 string into a ProfileId.
|
|
func ParseProfileId(s string) (ProfileId, bool) {
|
|
id, ok := uid.Parse(s)
|
|
return ProfileId(id), ok
|
|
}
|