Documentation
¶
Overview ¶
Package morpheus provides a single entry point for the Morpheus data transformation library.
Usage:
m := morpheus.New()
result, err := m.Transform("uppercase", "hello world")
// result = "HELLO WORLD"
result, err := m.TransformChain([]string{"trim", "uppercase"}, " hello ")
// result = "HELLO"
detections, err := m.DetectPII(data)
masked, err := m.MaskPII(data)
pipeline := morpheus.NewPipeline("etl").
AddStage(morpheus.NewStage("extract", "extractor", nil)).
AddStage(morpheus.NewStage("transform", "transformer", nil).DependsOn("extract"))
result, err := m.RunPipeline(pipeline, input)
Index ¶
- func DefaultRegistry() *entity.TransformerRegistry
- type Closeable
- type Format
- type Morpheus
- func (m *Morpheus) Convert(ctx context.Context, input any, from, to Format) (any, error)
- func (m *Morpheus) DetectPII(ctx context.Context, data any) ([]port.PIIDetectionResult, error)
- func (m *Morpheus) EvaluateRules(ctx context.Context, rules []string, data map[string]any) (map[string]any, []string, error)
- func (m *Morpheus) ListTransformers() []string
- func (m *Morpheus) MaskPII(ctx context.Context, data any) (any, error)
- func (m *Morpheus) RegisterTransformer(t entity.Transformer) error
- func (m *Morpheus) Registry() *entity.TransformerRegistry
- func (m *Morpheus) Shutdown() error
- func (m *Morpheus) Transform(name string, input any, params ...Params) (any, error)
- func (m *Morpheus) TransformChain(names []string, input any) (any, error)
- type Option
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultRegistry ¶
func DefaultRegistry() *entity.TransformerRegistry
DefaultRegistry returns a TransformerRegistry pre-loaded with all built-in zero-configuration transformers. Transformers that require parameters (like Replace, Add, Substring, SchemaValidator) are not included — register them yourself with the specific config you need.
registry := morpheus.DefaultRegistry()
t, _ := registry.Get("uppercase")
result, _ := t.Transform(ctx, "hello")
Types ¶
type Closeable ¶
type Closeable interface {
Close() error
}
Closeable is an optional interface that adapters can implement for graceful shutdown. If a cache or metrics adapter implements this, Shutdown() will call Close().
type Morpheus ¶
type Morpheus struct {
// contains filtered or unexported fields
}
Morpheus is the main entry point for the library. Create one with New() and use it to transform data.
func New ¶
New creates a new Morpheus instance with all built-in transformers registered. Use functional options to configure caching, metrics, etc.
m := morpheus.New() m := morpheus.New(morpheus.WithCacheTTL(10 * time.Minute))
func (*Morpheus) Convert ¶
Convert converts data between formats.
yaml, err := m.Convert(jsonData, morpheus.JSON, morpheus.YAML)
func (*Morpheus) DetectPII ¶
DetectPII scans data for personally identifiable information. Returns a list of detections with field paths and PII types.
detections, err := m.DetectPII(ctx, map[string]any{
"email": "john@example.com",
"ssn": "123-45-6789",
})
func (*Morpheus) EvaluateRules ¶
func (m *Morpheus) EvaluateRules(ctx context.Context, rules []string, data map[string]any) (map[string]any, []string, error)
EvaluateRules compiles YAML rules and evaluates data against them. Returns the modified data and a list of matched rule names.
ctx := context.Background()
rules := []string{`
rule: high_value
conditions:
- field: total
operator: greater_than
value: 1000
transformations:
- field: priority
transformer: set_value
params:
value: high
`}
result, matched, err := m.EvaluateRules(ctx, rules, data)
func (*Morpheus) ListTransformers ¶
ListTransformers returns all available transformer names.
func (*Morpheus) MaskPII ¶
MaskPII detects and masks PII in the data.
masked, err := m.MaskPII(ctx, map[string]any{
"email": "john@example.com",
})
// masked["email"] = "j***@example.com"
func (*Morpheus) RegisterTransformer ¶
func (m *Morpheus) RegisterTransformer(t entity.Transformer) error
RegisterTransformer adds a custom transformer to this instance.
m.RegisterTransformer(myCustomTransformer)
func (*Morpheus) Registry ¶
func (m *Morpheus) Registry() *entity.TransformerRegistry
Registry returns the transformer registry for advanced usage (registering custom transformers, listing available ones, etc.)
func (*Morpheus) Shutdown ¶
Shutdown gracefully shuts down all adapters that support it. Call this when your application is terminating.
m := morpheus.New(morpheus.WithCache(redisCache)) defer m.Shutdown()
func (*Morpheus) Transform ¶
Transform applies a named transformer to the input value.
result, err := m.Transform("upper_case", "hello")
// result = "HELLO"
result, err := m.Transform("add", 5, morpheus.Params{"amount": 3})
// result = 8
func (*Morpheus) TransformChain ¶
TransformChain applies multiple transformers in sequence. The output of each transformer becomes the input of the next.
result, err := m.TransformChain([]string{"trim", "upper_case", "slug"}, " Hello World ")
// result = "hello-world"
type Option ¶
type Option func(*Morpheus)
Option configures a Morpheus instance.
func WithCache ¶
WithCache sets a cache port for caching transformation results.
m := morpheus.New(morpheus.WithCache(myCache))
func WithCacheTTL ¶
WithCacheTTL sets the default cache TTL for transformation results. Default is 5 minutes.
m := morpheus.New(morpheus.WithCacheTTL(10 * time.Minute))
func WithMetrics ¶
func WithMetrics(metrics port.MetricsPort) Option
WithMetrics sets a metrics port for recording transformation metrics.
m := morpheus.New(morpheus.WithMetrics(myMetrics))
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01_config_driven_cache
command
|
|
|
02_config_driven_queue
command
|
|
|
03_transformer_factory
command
|
|
|
04_rule_engine_yaml
command
|
|
|
05_dag_pipeline
command
|
|
|
06_pii_workflow
command
|
|
|
07_production_ecommerce
command
|
|
|
pkg
|
|
|
adapter/cache/memory
Package memory provides an in-memory LRU cache with TTL expiration.
|
Package memory provides an in-memory LRU cache with TTL expiration. |
|
adapter/cache/multi_level
Package multilevel provides a multi-level cache (L1 memory + L2 Redis) with cache warming, stampede protection, and promotion between levels.
|
Package multilevel provides a multi-level cache (L1 memory + L2 Redis) with cache warming, stampede protection, and promotion between levels. |
|
adapter/cache/redis
Package redis provides a Redis-backed cache adapter implementing CachePort.
|
Package redis provides a Redis-backed cache adapter implementing CachePort. |
|
adapter/enrichment
Package enrichment provides OPTIONAL infrastructure adapters for data enrichment — fetching supplementary data from external sources (APIs, databases, Redis) to augment transformation inputs.
|
Package enrichment provides OPTIONAL infrastructure adapters for data enrichment — fetching supplementary data from external sources (APIs, databases, Redis) to augment transformation inputs. |
|
adapter/enrichment/api
Package api provides an HTTP API-based data enrichment adapter with rate limiting, health checks, and circuit breaker support.
|
Package api provides an HTTP API-based data enrichment adapter with rate limiting, health checks, and circuit breaker support. |
|
adapter/enrichment/database
Package database provides a database-backed data enrichment adapter with connection pooling and query building.
|
Package database provides a database-backed data enrichment adapter with connection pooling and query building. |
|
adapter/enrichment/redis
Package redis provides a Redis-backed data enrichment adapter for fast key-value lookups.
|
Package redis provides a Redis-backed data enrichment adapter for fast key-value lookups. |
|
adapter/enrichment/shared
Package shared provides shared utilities for enrichment adapters including circuit breaker and fallback strategies.
|
Package shared provides shared utilities for enrichment adapters including circuit breaker and fallback strategies. |
|
adapter/error
pkg/adapter/error/backoff.go
|
pkg/adapter/error/backoff.go |
|
adapter/function/local
Package local provides a local function executor that runs Go functions in-process without network calls.
|
Package local provides a local function executor that runs Go functions in-process without network calls. |
|
adapter/function/serverless
Package serverless provides serverless function executors for AWS Lambda, Azure Functions, and GCP Cloud Functions.
|
Package serverless provides serverless function executors for AWS Lambda, Azure Functions, and GCP Cloud Functions. |
|
adapter/metrics
Package metrics provides OPTIONAL infrastructure adapters for recording transformation metrics (in-memory, Prometheus, or async).
|
Package metrics provides OPTIONAL infrastructure adapters for recording transformation metrics (in-memory, Prometheus, or async). |
|
adapter/metrics/async
Package async provides a non-blocking metrics adapter with configurable buffer size and sampling rate for high-throughput applications.
|
Package async provides a non-blocking metrics adapter with configurable buffer size and sampling rate for high-throughput applications. |
|
adapter/metrics/memory
Package memory provides an in-memory metrics adapter for testing and development.
|
Package memory provides an in-memory metrics adapter for testing and development. |
|
adapter/metrics/prometheus
Package prometheus provides a Prometheus-compatible metrics adapter that exposes counters, gauges, and histograms via the Prometheus client.
|
Package prometheus provides a Prometheus-compatible metrics adapter that exposes counters, gauges, and histograms via the Prometheus client. |
|
adapter/pipeline/dag
Package dag provides a directed acyclic graph implementation for pipeline stage dependency resolution with cycle detection and topological sorting.
|
Package dag provides a directed acyclic graph implementation for pipeline stage dependency resolution with cycle detection and topological sorting. |
|
adapter/pipeline/orchestrator
Package orchestrator provides a DAG pipeline orchestrator that executes pipeline stages in topologically-sorted waves, running independent stages in parallel.
|
Package orchestrator provides a DAG pipeline orchestrator that executes pipeline stages in topologically-sorted waves, running independent stages in parallel. |
|
adapter/privacy
pkg/adapter/privacy/audit_logger.go
|
pkg/adapter/privacy/audit_logger.go |
|
adapter/queue
Package queue provides OPTIONAL infrastructure adapters for job queuing (in-memory or Redis-backed) with priority routing and backpressure.
|
Package queue provides OPTIONAL infrastructure adapters for job queuing (in-memory or Redis-backed) with priority routing and backpressure. |
|
adapter/queue/memory
Package memory provides an in-memory priority queue with worker pools, circuit breaker, and backpressure handling.
|
Package memory provides an in-memory priority queue with worker pools, circuit breaker, and backpressure handling. |
|
adapter/queue/redis
Package redis provides a Redis-backed queue adapter with priority routing and distributed worker support.
|
Package redis provides a Redis-backed queue adapter with priority routing and distributed worker support. |
|
adapter/queue/shared
Package shared provides shared types and utilities for queue adapters including configuration, backpressure, circuit breaker, and priority routing.
|
Package shared provides shared types and utilities for queue adapters including configuration, backpressure, circuit breaker, and priority routing. |
|
adapter/rule
Package rule provides a YAML-driven rule engine that compiles rules, indexes fields for fast lookup, evaluates conditions against data, and applies transformations when conditions match.
|
Package rule provides a YAML-driven rule engine that compiles rules, indexes fields for fast lookup, evaluates conditions against data, and applies transformations when conditions match. |
|
adapter/storage
Package storage provides OPTIONAL infrastructure adapters for persistent key-value storage (file-based or SQLite database).
|
Package storage provides OPTIONAL infrastructure adapters for persistent key-value storage (file-based or SQLite database). |
|
adapter/storage/database
Package database provides a SQLite-backed key-value storage adapter.
|
Package database provides a SQLite-backed key-value storage adapter. |
|
adapter/storage/file
Package file provides a file system-backed key-value storage adapter.
|
Package file provides a file system-backed key-value storage adapter. |
|
domain/entity
Package entity defines the core domain entities for the Morpheus library.
|
Package entity defines the core domain entities for the Morpheus library. |
|
domain/format
pkg/domain/format/converter.go
|
pkg/domain/format/converter.go |
|
domain/port
pkg/domain/port/audit_port.go
|
pkg/domain/port/audit_port.go |
|
domain/service
Package service provides domain services that orchestrate transformer execution.
|
Package service provides domain services that orchestrate transformer execution. |
|
domain/streaming
pkg/domain/streaming/csv_parser.go
|
pkg/domain/streaming/csv_parser.go |
|
domain/valueobject
Package valueobject defines immutable value objects used across the domain layer.
|
Package valueobject defines immutable value objects used across the domain layer. |
|
test
|
|
|
integration
test/integration/privacy_integration_helper.go
|
test/integration/privacy_integration_helper.go |
|
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |