mold

package
v0.38.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublishDictionaryChangedEvent added in v0.24.0

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

PublishDictionaryChangedEvent publishes a dictionary invalidation event. When no keys are provided, subscribers are expected to clear their entire cache.

Types

type CachedDictionaryResolver added in v0.24.0

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

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

func (*CachedDictionaryResolver) Resolve added in v0.24.0

func (r *CachedDictionaryResolver) Resolve(ctx context.Context, key, code string) (string, error)

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

type DictionaryChangedEvent added in v0.24.0

type DictionaryChangedEvent struct {
	// Keys lists the affected dictionary keys. When empty, all cached dictionaries should be cleared.
	Keys []string `json:"keys"`
}

DictionaryChangedEvent is emitted whenever dictionary entries need to be invalidated.

func (*DictionaryChangedEvent) EventType added in v0.24.0

func (*DictionaryChangedEvent) EventType() string

EventType implements event.Event.

type DictionaryLoader added in v0.24.0

type DictionaryLoader interface {
	// Load loads all dictionary entries for the given key, returning a code-to-name mapping.
	Load(ctx context.Context, key string) (map[string]string, error)
}

DictionaryLoader defines the contract for loading dictionary entries by key. Implementations should return a map where the key is the dictionary item's code and the value is the translated/display name.

type DictionaryLoaderFunc added in v0.24.0

type DictionaryLoaderFunc func(ctx context.Context, key string) (map[string]string, error)

DictionaryLoaderFunc allows using a plain function as a DictionaryLoader.

func (DictionaryLoaderFunc) Load added in v0.24.0

func (f DictionaryLoaderFunc) Load(ctx context.Context, key string) (map[string]string, error)

Load executes the wrapped function.

type DictionaryResolver added in v0.24.0

type DictionaryResolver interface {
	// Resolve resolves the corresponding name based on dictionary key and code value.
	// Returns the translated name and an error if resolution fails.
	Resolve(ctx context.Context, key, code string) (string, error)
}

DictionaryResolver defines the dictionary resolver interface for converting codes to readable names. Supports multi-level data dictionaries, using key to distinguish different dictionary types.

func NewCachedDictionaryResolver added in v0.24.0

func NewCachedDictionaryResolver(
	loader DictionaryLoader,
	bus event.Bus,
) DictionaryResolver

NewCachedDictionaryResolver constructs a caching resolver for dictionary 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