mold

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublishCodeSetChangedEvent added in v0.40.0

func PublishCodeSetChangedEvent(ctx context.Context, bus event.Bus, keys ...string) error

PublishCodeSetChangedEvent publishes a code set invalidation event. When no keys are provided, subscribers are expected to clear their entire cache.

Types

type CachedCodeSetResolver added in v0.40.0

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

CachedCodeSetResolver adds caching and event-based invalidation around a CodeSetLoader implementation. Underlying cache implementations already coordinate concurrent loads to prevent stampede.

func (*CachedCodeSetResolver) Resolve added in v0.40.0

func (r *CachedCodeSetResolver) Resolve(ctx context.Context, codeSet, code string) (string, error)

Resolve finds the display label for the provided code set/code combination. Returns the translated name and an error if resolution fails. Returns empty string without error if the code set or code is empty, or if the entry is not found.

type CodeInfo added in v0.40.0

type CodeInfo struct {
	// Code is the canonical code value.
	Code string `json:"code"`
	// Label is the code's display name.
	Label string `json:"label"`
}

CodeInfo describes one code within a code set.

type CodeSetChangedEvent added in v0.40.0

type CodeSetChangedEvent struct {
	// Keys lists the affected code set identifiers. When empty, all cached code sets should be cleared.
	Keys []string `json:"keys"`
}

CodeSetChangedEvent is emitted whenever code set entries need to be invalidated.

func (*CodeSetChangedEvent) EventType added in v0.40.0

func (*CodeSetChangedEvent) EventType() string

EventType implements event.Event.

type CodeSetInfo added in v0.40.0

type CodeSetInfo struct {
	// CodeSet is the code set identifier referenced by translate tags and
	// integration code maps (e.g. "gender").
	CodeSet string `json:"codeSet"`
	// Name is the code set's human-readable name.
	Name string `json:"name"`
}

CodeSetInfo describes one code set the host catalog exposes.

type CodeSetInspector added in v0.40.0

type CodeSetInspector interface {
	// ListCodeSets enumerates the code sets the host catalog exposes.
	ListCodeSets(ctx context.Context) ([]CodeSetInfo, error)
	// ListCodes enumerates one code set's codes with their display labels.
	ListCodes(ctx context.Context, codeSet string) ([]CodeInfo, error)
}

CodeSetInspector is the optional enumeration view of the host code set catalog. A host implements it alongside its CodeSetLoader (or a wholesale-replaced CodeSetResolver); consumers type-assert for it (mirroring event.StreamInspector) and degrade gracefully when it is absent.

type CodeSetLoader added in v0.40.0

type CodeSetLoader interface {
	// Load loads all codes for the given code set, returning a code-to-label mapping.
	Load(ctx context.Context, codeSet string) (map[string]string, error)
}

CodeSetLoader loads all codes of one code set as a code-to-label map.

type CodeSetLoaderFunc added in v0.40.0

type CodeSetLoaderFunc func(ctx context.Context, codeSet string) (map[string]string, error)

CodeSetLoaderFunc allows using a plain function as a CodeSetLoader.

func (CodeSetLoaderFunc) Load added in v0.40.0

func (f CodeSetLoaderFunc) Load(ctx context.Context, codeSet string) (map[string]string, error)

Load executes the wrapped function.

type CodeSetResolver added in v0.40.0

type CodeSetResolver interface {
	// Resolve resolves the display name for the given code set and code value.
	// Returns the translated name and an error if resolution fails.
	Resolve(ctx context.Context, codeSet, code string) (string, error)
}

CodeSetResolver resolves a code's display name within one host code set. Supports multiple code sets, using codeSet to distinguish between them.

func NewCachedCodeSetResolver added in v0.40.0

func NewCachedCodeSetResolver(
	loader CodeSetLoader,
	bus event.Bus,
) CodeSetResolver

NewCachedCodeSetResolver constructs a caching resolver for code set lookups.

type FieldLevel

type FieldLevel interface {
	// Transformer represents a subset of the current *Transformer that is executing the current transformation.
	Transformer() Transformer
	// Name returns the name of the current field being modified.
	Name() string
	// Parent returns the top level parent of the current value returned by Field().
	// This is used primarily for the ability to nil out pointer type values.
	// When several layers of abstraction are nested (e.g. an any wrapping an any),
	// it returns the first any.
	Parent() reflect.Value
	// Field returns the current field value being modified.
	Field() reflect.Value
	// Param returns the param associated wth the given function modifier.
	Param() string
	// SiblingField returns the sibling field value of the same struct by field name
	// Returns the field reflect.Value and a boolean indicating if the field exists
	SiblingField(name string) (reflect.Value, bool)
	// Struct returns the struct value that contains the current field.
	// The returned value is invalid when the field is transformed outside of a
	// struct walk (e.g. via Transformer.Field); callers must check IsValid.
	Struct() reflect.Value
}

FieldLevel represents the interface for field level modifier function.

type FieldTransformer

type FieldTransformer interface {
	// Tag returns the tag name corresponding to this transformer, used for referencing in struct tags
	Tag() string
	// Transform executes field transformation logic, fl provides field-level context information
	Transform(ctx context.Context, fl FieldLevel) error
}

FieldTransformer defines the field-level transformer interface for extending custom field transformation logic.

type Func

type Func func(ctx context.Context, fl FieldLevel) error

Func defines a transform function for use.

type Interceptor

type Interceptor interface {
	// Intercept intercepts the current value and returns the inner value that should be actually operated on
	Intercept(current reflect.Value) (inner reflect.Value)
}

Interceptor defines the interceptor interface for redirecting transformation operations of certain types to inner values For example: sql.NullString transformations should operate on its inner string value.

type InterceptorFunc

type InterceptorFunc func(current reflect.Value) (inner reflect.Value)

InterceptorFunc is a way to intercept custom types to redirect the functions to be applied to an inner typ/value. Eg. Sql.NullString, the manipulation should be done on the inner string.

type StructLevel

type StructLevel interface {
	// Transformer represents a subset of the current *Transformer that is executing the current transformation.
	Transformer() Transformer
	// Parent returns the top level parent of the current value returned by Struct().
	// This is used primarily for the ability to nil out pointer type values.
	// When several layers of abstraction are nested (e.g. an any wrapping an any),
	// it returns the first any.
	Parent() reflect.Value
	// Struct returns the value of the current struct being modified.
	Struct() reflect.Value
}

StructLevel represents the interface for struct level modifier function.

type StructLevelFunc

type StructLevelFunc func(ctx context.Context, sl StructLevel) error

StructLevelFunc accepts all values needed for struct level manipulation.

Why does this exist? For structs for which you may not have access or rights to add tags too, from other packages your using.

type StructTransformer

type StructTransformer interface {
	// Transform executes struct-level transformation logic, sl provides struct-level context information
	Transform(ctx context.Context, sl StructLevel) error
}

StructTransformer defines the struct-level transformer interface for custom processing of entire structs.

type Transformer

type Transformer interface {
	// Struct applies transformations to the entire struct based on field tags
	Struct(ctx context.Context, value any) error
	// Field applies specified transformation tags to a single field
	Field(ctx context.Context, value any, tags string) error
}

Transformer defines the main interface for struct transformers that provide tag-based data transformation.

type Translator

type Translator interface {
	// Supports returns true if the translator supports the given kind
	Supports(kind string) bool
	// Translate translates the current value to the corresponding description
	Translate(ctx context.Context, kind, value string) (string, error)
}

Translator translates field values to human-readable descriptions based on kind.

Jump to

Keyboard shortcuts

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