id

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package id defines TypeID-based identity types for all Shield entities.

Every entity in Shield uses a single ID struct with a prefix that identifies the entity type. IDs are K-sortable (UUIDv7-based), globally unique, and URL-safe in the format "prefix_suffix".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyID

type AnyID = ID

AnyID is a type alias that accepts any valid prefix.

type AwarenessID

type AwarenessID = ID

AwarenessID is a type-safe identifier for awareness detectors (prefix: "awr").

type BoundaryID

type BoundaryID = ID

BoundaryID is a type-safe identifier for boundaries (prefix: "bnd").

type CheckID

type CheckID = ID

CheckID is a type-safe identifier for safety checks (prefix: "schk").

type ComplianceReportID

type ComplianceReportID = ID

ComplianceReportID is a type-safe identifier for compliance reports (prefix: "crpt").

type FindingID

type FindingID = ID

FindingID is a type-safe identifier for findings (prefix: "find").

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID is the primary identifier type for all Shield entities. It wraps a TypeID providing a prefix-qualified, globally unique, sortable, URL-safe identifier in the format "prefix_suffix".

var Nil ID

Nil is the zero-value ID.

func MustParse

func MustParse(s string) ID

MustParse is like Parse but panics on error. Use for hardcoded ID values.

func MustParseWithPrefix

func MustParseWithPrefix(s string, expected Prefix) ID

MustParseWithPrefix is like ParseWithPrefix but panics on error.

func New

func New(prefix Prefix) ID

New generates a new globally unique ID with the given prefix. It panics if prefix is not a valid TypeID prefix (programming error).

func NewAwarenessID

func NewAwarenessID() ID

NewAwarenessID generates a new unique awareness ID.

func NewBoundaryID

func NewBoundaryID() ID

NewBoundaryID generates a new unique boundary ID.

func NewCheckID

func NewCheckID() ID

NewCheckID generates a new unique safety check ID.

func NewComplianceReportID

func NewComplianceReportID() ID

NewComplianceReportID generates a new unique compliance report ID.

func NewFindingID

func NewFindingID() ID

NewFindingID generates a new unique finding ID.

func NewInstinctID

func NewInstinctID() ID

NewInstinctID generates a new unique instinct ID.

func NewJudgmentID

func NewJudgmentID() ID

NewJudgmentID generates a new unique judgment ID.

func NewPIITokenID

func NewPIITokenID() ID

NewPIITokenID generates a new unique PII token ID.

func NewPolicyID

func NewPolicyID() ID

NewPolicyID generates a new unique policy ID.

func NewReflexID

func NewReflexID() ID

NewReflexID generates a new unique reflex ID.

func NewSafetyProfileID

func NewSafetyProfileID() ID

NewSafetyProfileID generates a new unique safety profile ID.

func NewScanID

func NewScanID() ID

NewScanID generates a new unique scan ID.

func NewValueID

func NewValueID() ID

NewValueID generates a new unique value ID.

func Parse

func Parse(s string) (ID, error)

Parse parses a TypeID string (e.g., "scan_01h2xcejqtf2nbrexx3vqjhp41") into an ID. Returns an error if the string is not valid.

func ParseAny

func ParseAny(s string) (ID, error)

ParseAny parses a string into an ID without type checking the prefix.

func ParseAwarenessID

func ParseAwarenessID(s string) (ID, error)

ParseAwarenessID parses a string and validates the "awr" prefix.

func ParseBoundaryID

func ParseBoundaryID(s string) (ID, error)

ParseBoundaryID parses a string and validates the "bnd" prefix.

func ParseCheckID

func ParseCheckID(s string) (ID, error)

ParseCheckID parses a string and validates the "schk" prefix.

func ParseComplianceReportID

func ParseComplianceReportID(s string) (ID, error)

ParseComplianceReportID parses a string and validates the "crpt" prefix.

func ParseFindingID

func ParseFindingID(s string) (ID, error)

ParseFindingID parses a string and validates the "find" prefix.

func ParseInstinctID

func ParseInstinctID(s string) (ID, error)

ParseInstinctID parses a string and validates the "inst" prefix.

func ParseJudgmentID

func ParseJudgmentID(s string) (ID, error)

ParseJudgmentID parses a string and validates the "jdg" prefix.

func ParsePIITokenID

func ParsePIITokenID(s string) (ID, error)

ParsePIITokenID parses a string and validates the "pii" prefix.

func ParsePolicyID

func ParsePolicyID(s string) (ID, error)

ParsePolicyID parses a string and validates the "pol" prefix.

func ParseReflexID

func ParseReflexID(s string) (ID, error)

ParseReflexID parses a string and validates the "rflx" prefix.

func ParseSafetyProfileID

func ParseSafetyProfileID(s string) (ID, error)

ParseSafetyProfileID parses a string and validates the "sprf" prefix.

func ParseScanID

func ParseScanID(s string) (ID, error)

ParseScanID parses a string and validates the "scan" prefix.

func ParseValueID

func ParseValueID(s string) (ID, error)

ParseValueID parses a string and validates the "val" prefix.

func ParseWithPrefix

func ParseWithPrefix(s string, expected Prefix) (ID, error)

ParseWithPrefix parses a TypeID string and validates that its prefix matches the expected value.

func (ID) IsNil

func (i ID) IsNil() bool

IsNil reports whether this ID is the zero value.

func (ID) MarshalBSONValue

func (i ID) MarshalBSONValue() (bsonType byte, data []byte, err error)

MarshalBSONValue satisfies bson.ValueMarshaler (mongo-driver v2) so the ID is stored as a BSON string instead of an opaque struct. No bson import needed because Go uses structural typing for interface satisfaction.

func (ID) MarshalText

func (i ID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (ID) Prefix

func (i ID) Prefix() Prefix

Prefix returns the prefix component of this ID.

func (*ID) Scan

func (i *ID) Scan(src any) error

Scan implements sql.Scanner for database retrieval.

func (ID) String

func (i ID) String() string

String returns the full TypeID string representation (prefix_suffix). Returns an empty string for the Nil ID.

func (*ID) UnmarshalBSONValue

func (i *ID) UnmarshalBSONValue(t byte, data []byte) error

UnmarshalBSONValue satisfies bson.ValueUnmarshaler (mongo-driver v2).

func (*ID) UnmarshalText

func (i *ID) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (ID) Value

func (i ID) Value() (driver.Value, error)

Value implements driver.Valuer for database storage. Returns nil for the Nil ID so that optional foreign key columns store NULL.

type InstinctID

type InstinctID = ID

InstinctID is a type-safe identifier for instincts (prefix: "inst").

type JudgmentID

type JudgmentID = ID

JudgmentID is a type-safe identifier for judgments (prefix: "jdg").

type PIITokenID

type PIITokenID = ID

PIITokenID is a type-safe identifier for PII tokens (prefix: "pii").

type PolicyID

type PolicyID = ID

PolicyID is a type-safe identifier for policies (prefix: "pol").

type Prefix

type Prefix string

Prefix identifies the entity type encoded in a TypeID.

const (
	PrefixScan             Prefix = "scan"
	PrefixPolicy           Prefix = "pol"
	PrefixFinding          Prefix = "find"
	PrefixPIIToken         Prefix = "pii"
	PrefixComplianceReport Prefix = "crpt"
	PrefixCheck            Prefix = "schk"
	PrefixInstinct         Prefix = "inst"
	PrefixJudgment         Prefix = "jdg"
	PrefixAwareness        Prefix = "awr"
	PrefixValue            Prefix = "val"
	PrefixReflex           Prefix = "rflx"
	PrefixBoundary         Prefix = "bnd"
	PrefixSafetyProfile    Prefix = "sprf"
)

Prefix constants for all Shield entity types.

type ReflexID

type ReflexID = ID

ReflexID is a type-safe identifier for reflexes (prefix: "rflx").

type SafetyProfileID

type SafetyProfileID = ID

SafetyProfileID is a type-safe identifier for safety profiles (prefix: "sprf").

type ScanID

type ScanID = ID

ScanID is a type-safe identifier for scan results (prefix: "scan").

type ValueID

type ValueID = ID

ValueID is a type-safe identifier for values (prefix: "val").

Jump to

Keyboard shortcuts

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