core

package
v0.0.0-...-ecee8c2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package core holds the foundation every layer shares: identifiers, the clock, the error taxonomy and the tenant carried by a context. It imports nothing else from this module. See docs/architecture/overview.md §3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRetryable

func IsRetryable(err error) bool

IsRetryable reports whether err is marked retryable.

func ValidKind

func ValidKind(kind string) bool

ValidKind reports whether kind may prefix an identifier.

func WithTenant

func WithTenant(ctx context.Context, id TenantID) context.Context

WithTenant returns a context that carries id as the tenant. A later call on the same context replaces the earlier id; the parent context is unchanged. Every id is stored as is, valid or invalid: TenantFrom decides validity when the context is read, so an invalid id reads as no tenant.

Types

type Clock

type Clock interface {
	Now() time.Time
}

Clock is the only source of wall time for production code outside the composition root. Durable flow code uses DurableContext.Now instead.

type Code

type Code string

Code is a closed, stable error taxonomy shared by every layer and mapped to API problem responses. Add codes; never rename or remove them.

const (
	CodeInvalidArgument   Code = "invalid_argument"
	CodeNotFound          Code = "not_found"
	CodeConflict          Code = "conflict"
	CodePermissionDenied  Code = "permission_denied"
	CodeUnauthenticated   Code = "unauthenticated"
	CodeBudgetExceeded    Code = "budget_exceeded"
	CodeRateLimited       Code = "rate_limited"
	CodeTimeout           Code = "timeout"
	CodeUnavailable       Code = "unavailable"
	CodeUnsupported       Code = "unsupported"
	CodeVendor            Code = "vendor_error"
	CodeAmbiguousStart    Code = "ambiguous_start"
	CodeCancelled         Code = "cancelled"
	CodeInternal          Code = "internal"
	CodeRecordingMissing  Code = "recording_missing"
	CodeDeterminismBroken Code = "determinism_violation"
)

func CodeOf

func CodeOf(err error) Code

CodeOf returns the platform code of err, or CodeInternal.

type Error

type Error struct {
	Code       Code
	Message    string         // English, for logs; never shown to end users as-is
	Retryable  bool           // safe to retry the same request
	RetryAfter time.Duration  // provider hint, zero when unknown
	MessageKey string         // i18n key for user-facing text, optional
	Params     map[string]any // i18n params; must not contain secrets
	Details    map[string]any // redacted before leaving the process
	Cause      error
}

Error is the platform error. It carries retry semantics (for runtimes and clients) and an optional message key (for localized presentation at the edge).

func NewError

func NewError(code Code, msg string, details map[string]any) *Error

NewError builds a non-retryable error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Ids

type Ids interface {
	New(kind string) (string, error)
}

Ids issues entity identifiers of the form "<kind>_<26 Crockford base32 chars>".

Identifiers are unique across process restarts and sort lexicographically by creation time (REQ-CORE-001, REQ-CORE-002). Production code obtains an Ids from the composition root; deterministic fakes live in core/coretest and are importable from tests only (enforced by `gate layering`).

type SystemClock

type SystemClock struct{}

SystemClock reads the operating-system clock.

func (SystemClock) After

func (SystemClock) After(d time.Duration) <-chan time.Time

After returns a channel that receives once after d on the system clock.

func (SystemClock) Now

func (SystemClock) Now() time.Time

Now returns the current UTC time.

type TenantID

type TenantID string

TenantID identifies the tenant a call acts for: the isolation boundary for data and spend. Every layer reads it from the context with TenantFrom, which reports no tenant for an id outside the grammar (REQ-CORE-005).

func TenantFrom

func TenantFrom(ctx context.Context) (TenantID, bool)

TenantFrom returns the tenant carried by ctx, and false when ctx is nil, carries no id, or carries an id that is not a valid tenant id. Callers that must not run without a tenant check the second result instead of comparing against "".

A valid id satisfies REQ-CORE-005: non-empty, at most 128 bytes, valid UTF-8, free of control characters from U+0000 to U+001F and U+007F, neither "." nor "..", free of "/" and "\", and neither begins nor ends with a Unicode White_Space character. Dots and whitespace inside a longer id are allowed. An invalid id never falls back to the parent context's id: it reports no tenant.

type ULIDs

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

ULIDs is the production Ids implementation: ULIDs with cryptographic entropy, monotonic within one millisecond in one process.

func NewULIDs

func NewULIDs(clock Clock, entropy io.Reader) *ULIDs

NewULIDs returns a ULID generator. A nil entropy source uses crypto/rand.

func (*ULIDs) New

func (g *ULIDs) New(kind string) (string, error)

New returns a fresh identifier for kind.

Directories

Path Synopsis
Package coretest holds deterministic fakes for core ports.
Package coretest holds deterministic fakes for core ports.
Package schema generates JSON Schema from Go types, compiles and validates instances, and produces RFC 8785 canonical JSON for content-addressing.
Package schema generates JSON Schema from Go types, compiles and validates instances, and produces RFC 8785 canonical JSON for content-addressing.

Jump to

Keyboard shortcuts

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