Documentation
¶
Overview ¶
Package rid generates resource identifiers.
Format: {prefix}_{base62_id}
Default length is 12 base62 chars → 3.2×10²¹ space. Prefix constraints: 1–10 chars, [a-z][a-z0-9]*, total RID length ≤ 23.
Index ¶
- func HasPrefix(rid, expect string) bool
- func New(prefix string) string
- func NewRaw() string
- func NewWithLength(prefix string, n int) string
- func Parse(rid string) (prefix, id string, err error)
- func Prefix(rid string) string
- func ValidatePrefix(prefix string, idLen int) error
- func ValidateRID(s string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWithLength ¶
NewWithLength generates a prefixed RID with custom ID length. Panics if prefix is invalid or total length exceeds 23.
func Parse ¶
Parse splits a RID into prefix and id parts. Returns error if the RID has no underscore separator.
func Prefix ¶
Prefix extracts the prefix from a RID. Returns empty string if no underscore is found.
func ValidatePrefix ¶
ValidatePrefix checks prefix constraints without generating an ID. idLen is the intended random part length (used for total-length check). Returns nil if valid, error describing the problem otherwise.
func ValidateRID ¶
ValidateRID checks whether a full RID conforms to the schema:
- total length 1–maxRIDLen
- shape either "id" (no prefix) or "prefix_id" where prefix is valid per ValidatePrefix and id is at least one character of [A-Za-z0-9]
Used by callers (e.g. db.Model.BeforeCreate) to reject malformed user-supplied RIDs before they reach the database.
Types ¶
This section is empty.