mapper

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mapper renders mapping configurations with Go templates and helper functions. It is used to transform arbitrary input data into typed structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtraMappedData

type ExtraMappedData struct {
	APIVersion string
	ItemFamily string
	Identifier string
	Spec       map[string]any
}

ExtraMappedData wraps the identifier and rendered spec produced by a Mapper.

type ExtraMapping

type ExtraMapping struct {
	APIVersion       string
	ItemFamily       string
	DeletePolicy     string
	CreateIfTemplate *template.Template
	IDTemplate       *template.Template
	BodyTemplate     *template.Template
}

ExtraMapping defines a pre-compiled template for an extra item.

type MappedData

type MappedData struct {
	Identifier string
	Metadata   map[string]any
	Spec       map[string]any
}

MappedData wraps the identifier and rendered spec produced by a Mapper.

type Mapper

type Mapper interface {
	// ApplyTemplates applies the mapper templates to the given input data and returns the mapped output.
	ApplyTemplates(input map[string]any, parentItemInfo ParentItemInfo) (output MappedData, extra []ExtraMappedData, err error)
	// ApplyIdentifierTemplate applies only the identifier template to the given input data and returns
	ApplyIdentifierTemplate(data map[string]any) (string, []ExtraMappedData, error)
}

Mapper renders input data into templated output structures. Implementations must provide an identifier template that yields a unique key per entity. Template strings are evaluated using Go's text/template engine.

func New

func New(identifierTemplate string, metadataTemplates, specTemplates map[string]string, extraTemplates []config.Extra) (Mapper, error)

New constructs a Mapper using the provided identifier template and spec templates.

type ParentItemInfo

type ParentItemInfo struct {
	Identifier string
	APIVersion string
	ItemFamily string
}

ParentItemInfo holds metadata about the parent item for relationship extra mappings.

type ParsingError

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

ParsingError wraps failures that happen while compiling mapper templates.

func NewParsingError

func NewParsingError(err error) *ParsingError

NewParsingError builds a ParsingError from the underlying parsing error chain.

func (*ParsingError) Error

func (e *ParsingError) Error() string

func (*ParsingError) Is

func (e *ParsingError) Is(target error) bool

func (*ParsingError) Unwrap

func (e *ParsingError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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