Help us shape the future of Go! Take the 2026 Go Developer Survey

mapping

package
v1.26.6 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAndRecord

func CheckAndRecord(cfg *MappingConfig) (correlationID string, done func(success bool), err error)

CheckAndRecord verifies loop guard rules (Layers 2+4) and records the new run. Returns a correlation ID and a cleanup function that marks the run as completed. Returns an error if the run should be blocked.

func Execute

func Execute(ctx context.Context, cfg *MappingConfig, pkt *packet.DataPacket, dryRun bool) error

Execute applies cfg to pkt: remaps fields for each target and upserts into the target DB. When dryRun is true the transformation is performed but no data is written.

func ExecuteWithOptions

func ExecuteWithOptions(ctx context.Context, cfg *MappingConfig, pkt *packet.DataPacket, opts ExecOptions) error

ExecuteWithOptions is Execute with room for settings that are not "dry run".

Types

type ConnConfig

type ConnConfig struct {
	Type   string `yaml:"type"` // "postgres", "mssql", "sqlite"
	DSN    string `yaml:"dsn"`
	Schema string `yaml:"schema,omitempty"` // default schema; overridden by dotted table names
}

ConnConfig describes a target database connection.

type ExecOptions

type ExecOptions struct {
	// DryRun performs the transformation without writing anything.
	DryRun bool

	// Quiet drops the per-target progress line. The caller reports the result
	// instead — a drain that consumes forty messages should not print forty
	// lines when the scheduler only wants the total.
	Quiet bool
	// Output receives the dry-run plan and progress. Nil keeps stdout for v1.
	Output io.Writer
}

ExecOptions controls a mapping run.

type FieldMapping

type FieldMapping struct {
	From string            `yaml:"from"`
	To   string            `yaml:"to"`
	Enum map[string]string `yaml:"enum,omitempty"` // value remap: source value → target value
}

FieldMapping describes a single field transformation.

type InputSource

type InputSource struct {
	Type   string            `yaml:"type"` // "s3" | "broker"
	S3     *storage.S3Config `yaml:"s3,omitempty"`
	Broker *brokers.Config   `yaml:"broker,omitempty"`
}

InputSource describes where the input TDTP packet comes from. When absent from the mapping YAML, --input must be a local file path.

type LoopGuard

type LoopGuard struct {
	SourceSystem string `yaml:"source_system"`
	TargetSystem string `yaml:"target_system"`
	MinInterval  string `yaml:"min_interval"` // e.g. "10s", "1m"
}

LoopGuard prevents recursive sync loops between systems.

type MappingConfig

type MappingConfig struct {
	ID          string       `yaml:"id"`
	Version     string       `yaml:"version"`
	ApprovedBy  string       `yaml:"approved_by,omitempty"`
	LoopGuard   LoopGuard    `yaml:"loop_guard"`
	InputSource *InputSource `yaml:"input_source,omitempty"`
	TargetConn  ConnConfig   `yaml:"target_connection"`
	Targets     []Target     `yaml:"targets"`
}

MappingConfig is the top-level structure parsed from a mapping YAML file.

func ParseFile

func ParseFile(path string) (*MappingConfig, error)

ParseFile reads and validates a mapping YAML file.

type Target

type Target struct {
	ID        string         `yaml:"id"`
	Table     string         `yaml:"table"`
	UpsertKey string         `yaml:"upsert_key"` // field name used for ON CONFLICT
	Fields    []FieldMapping `yaml:"fields"`
}

Target describes one output table and its field mappings.

Jump to

Keyboard shortcuts

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