Documentation
¶
Index ¶
- func PublishDataDictChangedEvent(publisher event.Publisher, keys ...string)
- type CachedDataDictResolver
- type DataDictChangedEvent
- type DataDictLoader
- type DataDictLoaderFunc
- type DataDictResolver
- type FieldLevel
- type FieldTransformer
- type Func
- type Interceptor
- type InterceptorFunc
- type StructLevel
- type StructLevelFunc
- type StructTransformer
- type Transformer
- type Translator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PublishDataDictChangedEvent ¶
PublishDataDictChangedEvent publishes a dictionary invalidation event. When no keys are provided, subscribers are expected to clear their entire cache.
Types ¶
type CachedDataDictResolver ¶
type CachedDataDictResolver struct {
// contains filtered or unexported fields
}
CachedDataDictResolver adds caching and event-based invalidation around a DataDictLoader implementation. Underlying cache implementations already coordinate concurrent loads to prevent stampede.
type DataDictChangedEvent ¶
type DataDictChangedEvent struct {
event.BaseEvent
// Keys lists the affected dictionary keys. When empty, all cached dictionaries should be cleared.
Keys []string `json:"keys"`
}
DataDictChangedEvent is emitted whenever dictionary entries need to be invalidated.
type DataDictLoader ¶
DataDictLoader 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 DataDictLoaderFunc ¶
DataDictLoaderFunc allows using a plain function as a DataDictLoader.
type DataDictResolver ¶
type DataDictResolver 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)
}
DataDictResolver defines the data dictionary resolver interface for converting codes to readable names Supports multi-level data dictionaries, using key to distinguish different dictionary types.
func NewCachedDataDictResolver ¶
func NewCachedDataDictResolver( loader DataDictLoader, bus event.Subscriber, ) DataDictResolver
NewCachedDataDictResolver 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 return by Field()
//
// This is used primarily for having the ability to nil out pointer type values.
//
// NOTE: that is there are several layers of abstractions eg. interface{} of interface{} of interface{} this
// function returns the first interface{}
//
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)
}
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 ¶
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 return by Struct().
//
// This is used primarily for having the ability to nil out pointer type values.
//
// NOTE: that is there are several layers of abstractions eg. interface{} of interface{} of interface{} this
// function returns the first interface{}.
//
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.