idHelpers

package
v1.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 10 Imported by: 14

README

idHelpers

idHelpers provides helpers for generating, formatting, and normalising IDs.

It includes both hashing helpers (for stable/derived IDs) and KSUID-based helpers (for globally unique, time-sortable IDs).

Key functions

  • Encode(string) string
    • Produces a SHA3-256 hex digest of a path-safe version of the input.
  • Decode(string) string
    • Reverses path-safe encoding via htmlHelpers.FromPathSafe.
  • GetUUIDv2() string
    • Returns a KSUID string.
  • GetUUIDv2WithPayload(payload string) (string, error)
    • Returns a KSUID containing up to 16 bytes of payload.
  • GetUUIDv2Payload(uuid string) string
    • Extracts a KSUID payload.
  • InspectUUIDv2(uuid string) string
    • Human-readable KSUID summary.
  • BuildCompositeID(part ...interface{}) (compositeID string, encodedCompositeID string, err error)
    • Builds a delimiter-joined composite ID plus a hashed version.
  • SanitizeID(id string) string
    • Normalises identifiers (camel-case, removes special chars, strips separators).

Example

import "github.com/mt1976/frantic-core/idHelpers"

func example() {
    raw := "Customer 123"
    stable := idHelpers.Encode(raw)

    uuid := idHelpers.GetUUIDv2()

    composite, compositeHash, _ := idHelpers.BuildCompositeID("customer", 123)
    _, _, _ = composite, compositeHash, stable
    _ = uuid
}

Documentation

Overview

Package idHelpers provides helpers for generating and formatting IDs.

Index

Constants

This section is empty.

Variables

View Source
var DELIMITER string
View Source
var SEP string = "⋮"

Functions

func BuildCompositeID added in v1.3.4

func BuildCompositeID(part ...any) (compositeID string, encodedCompositeID string, err error)

BuildCompositeID builds a composite identifier by sanitizing each part and joining them with the configured delimiter. It also returns the encoded (hashed) form of the composite ID.

func Decode

func Decode(in string) string

Decode reverses a path-safe transformation applied by `htmlHelpers.ToPathSafe`. If decoding fails, it logs the error and returns an empty string.

func Encode

func Encode(in string) string

Encode returns a SHA3-256 hex digest of a path-safe version of the input. It trims spaces, removes internal spaces, converts to a path-safe string, and then hashes the result. On error, it logs and returns an empty string.

func GetUUID

func GetUUID() string

GetUUID returns a legacy time-based identifier string comprising the current date/time, process UID (if available), and a random component. It is intended for human-readable tracing rather than cryptographic uniqueness.

func GetUUIDv2

func GetUUIDv2() string

GetUUIDv2 generates a KSUID (K-Sortable Unique ID) and returns it as a string. KSUIDs are globally unique and time-sortable identifiers.

func GetUUIDv2Payload

func GetUUIDv2Payload(uuid string) string

GetUUIDv2Payload extracts and returns the payload from a KSUID string. If parsing fails, it logs the error and returns an empty string.

func GetUUIDv2WithPayload

func GetUUIDv2WithPayload(payload string) (string, error)

GetUUIDv2WithPayload generates a KSUID containing a fixed-size payload. The payload is right-padded to 16 bytes if shorter and must not exceed 16 bytes. Returns the KSUID string or an error if generation fails.

func InspectUUIDv2

func InspectUUIDv2(uuid string) string

InspectUUIDv2 returns a human-readable summary of a KSUID including its time and payload contents. Returns an empty string if parsing fails.

func ParseCompositeID added in v1.3.4

func ParseCompositeID(compositeID string) string

ParseCompositeID is a placeholder that will parse a composite ID back into its constituent parts. Currently returns an empty string.

func SanitizeID added in v1.3.4

func SanitizeID(id string) string

SanitizeID normalizes an identifier by camel-casing, removing special characters, trimming whitespace, and stripping underscores/hyphens. If the input appears to be a hash (example length), it is lowercased.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL