jmes

package
v0.0.0-...-b47ff69 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

Package jmes implements the transform template using JMESPath templates.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedFieldMappingType = errors.New("unsupported field mapping type")
	ErrFieldMappingEntryMalformed  = errors.New("field mapping entry is malformed")
	ErrFieldMappingEntryRequired   = errors.New("field mapping entry must not be empty")
	ErrFieldMappingObjectRequired  = errors.New("field mapping object must not be null")
)

Functions

func EvaluateObjectFieldMappingEntries

func EvaluateObjectFieldMappingEntries(
	input map[string]FieldMappingEntryConfig,
	getEnvFunc goenvconf.GetEnvFunc,
) (map[string]FieldMappingEntry, error)

EvaluateObjectFieldMappingEntries validate and resolve the entry mapping fields of an object.

func EvaluateObjectFieldMappingStringEntries

func EvaluateObjectFieldMappingStringEntries(
	input map[string]FieldMappingEntryStringConfig,
	getEnvFunc goenvconf.GetEnvFunc,
) (map[string]FieldMappingEntryString, error)

EvaluateObjectFieldMappingStringEntries validate and resolve the entry mapping for string fields of an object.

Types

type FieldMapping

type FieldMapping struct {
	FieldMappingInterface
}

FieldMapping is a wrapper of a field mapping interface to evaluate data.

func NewFieldMapping

func NewFieldMapping(inner FieldMappingInterface) FieldMapping

NewFieldMapping creates a new field mapping instance.

func (FieldMapping) Equal

func (fm FieldMapping) Equal(target FieldMapping) bool

Equal checks if this instance equals the target value.

func (FieldMapping) Interface

func (fm FieldMapping) Interface() FieldMappingInterface

Interface returns the inner field mapping interface.

func (FieldMapping) IsZero

func (fm FieldMapping) IsZero() bool

IsZero checks if the field mapping is empty or zero-valued.

type FieldMappingConfig

type FieldMappingConfig struct {
	FieldMappingConfigInterface `yaml:",inline"`
}

FieldMappingConfig represents a generic field mapping config.

func NewFieldMappingConfig

func NewFieldMappingConfig(inner FieldMappingConfigInterface) FieldMappingConfig

NewFieldMappingConfig creates a new FieldMappingConfig instance.

func (FieldMappingConfig) Equal

func (fm FieldMappingConfig) Equal(target FieldMappingConfig) bool

Equal checks if this instance equals the target value.

func (FieldMappingConfig) Interface

Interface returns the underlying config interface.

func (FieldMappingConfig) IsZero

func (fm FieldMappingConfig) IsZero() bool

IsZero checks if the config is empty.

func (*FieldMappingConfig) UnmarshalJSON

func (fm *FieldMappingConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*FieldMappingConfig) UnmarshalYAML

func (fm *FieldMappingConfig) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the custom behavior for the yaml.Unmarshaler interface.

type FieldMappingConfigInterface

type FieldMappingConfigInterface interface {
	Type() FieldMappingType
	Evaluate(getEnvFunc goenvconf.GetEnvFunc) (FieldMapping, error)
	EvaluateEnv() (FieldMapping, error)
}

FieldMappingConfigInterface abstracts the interface of a field mapping config.

type FieldMappingEntry

type FieldMappingEntry struct {
	// Path is a JMESPath expression to find a value in the input data.
	Path *string
	// Default value to be used when no value is found when looking up the value using the path.
	Default any
}

FieldMappingEntry is the entry to lookup field values with the specified JMES path.

func (FieldMappingEntry) Equal

func (fm FieldMappingEntry) Equal(target FieldMappingEntry) bool

Equal checks if this instance equals the target value.

func (FieldMappingEntry) Evaluate

func (fm FieldMappingEntry) Evaluate(data any) (any, error)

Evaluate validates and transforms data with the specified JMES path.

func (FieldMappingEntry) IsZero

func (fm FieldMappingEntry) IsZero() bool

IsZero checks if the field mapping entry is empty (zero-valued).

func (FieldMappingEntry) Type

Type returns type of the field mapping entry.

type FieldMappingEntryConfig

type FieldMappingEntryConfig struct {
	// Path is a JMESPath expression to find a value in the input data.
	Path *string `json:"path,omitempty" yaml:"path,omitempty" jsonschema:"description=JMESPath expression to find a value in the input data"`
	// Default value to be used when no value is found when looking up the value using the path.
	Default *goenvconf.EnvAny `json:"default,omitempty" yaml:"default,omitempty" jsonschema:"description=Default value to be used when no value is found"`
}

FieldMappingEntryConfig is the entry config to lookup field values with the specified JMES path.

func (FieldMappingEntryConfig) Equal

Equal checks if this instance equals the target value.

func (FieldMappingEntryConfig) Evaluate

func (fm FieldMappingEntryConfig) Evaluate(getEnvFunc goenvconf.GetEnvFunc) (FieldMapping, error)

Evaluate converts the config to the field mapping instance with a custom env loader.

func (FieldMappingEntryConfig) EvaluateEntry

func (fm FieldMappingEntryConfig) EvaluateEntry(
	getEnvFunc goenvconf.GetEnvFunc,
) (FieldMappingEntry, error)

EvaluateEntry converts the config to the field mapping entry instance with a custom env loader.

func (FieldMappingEntryConfig) EvaluateEntryEnv

func (fm FieldMappingEntryConfig) EvaluateEntryEnv() (FieldMappingEntry, error)

EvaluateEntryEnv converts the config to the field mapping entry instance.

func (FieldMappingEntryConfig) EvaluateEnv

func (fm FieldMappingEntryConfig) EvaluateEnv() (FieldMapping, error)

EvaluateEnv converts the config to the field mapping instance with environment variables.

func (FieldMappingEntryConfig) IsZero

func (fm FieldMappingEntryConfig) IsZero() bool

IsZero checks if the config is empty.

func (FieldMappingEntryConfig) Type

Type returns the type of field mapping config.

type FieldMappingEntryString

type FieldMappingEntryString struct {
	// Path is a JMESPath expression to find a value in the input data.
	Path *string
	// Default value to be used when no value is found when looking up the value using the path.
	Default *string
}

FieldMappingEntryString is the entry to lookup string values with the specified JMES path.

func (FieldMappingEntryString) Equal

Equal checks if this instance equals the target value.

func (FieldMappingEntryString) Evaluate

func (fm FieldMappingEntryString) Evaluate(data any) (any, error)

Evaluate validates and transforms data with the specified JMES path, returning any value.

func (FieldMappingEntryString) EvaluateString

func (fm FieldMappingEntryString) EvaluateString(data any) (*string, error)

EvaluateString validates and transforms data with the specified JMES path, returning string value explicitly.

func (FieldMappingEntryString) IsZero

func (fm FieldMappingEntryString) IsZero() bool

IsZero checks if the field mapping entry string is empty or zero-valued.

func (FieldMappingEntryString) Type

Type returns type of the field mapping entry string.

type FieldMappingEntryStringConfig

type FieldMappingEntryStringConfig struct {
	// Path is a JMESPath expression to find a value in the input data.
	Path *string `json:"path,omitempty" yaml:"path,omitempty"`
	// Default value to be used when no value is found when looking up the value using the path.
	Default *goenvconf.EnvString `json:"default,omitempty" yaml:"default,omitempty"`
}

FieldMappingEntryStringConfig is the entry config to lookup string values with the specified JMES path.

func (FieldMappingEntryStringConfig) Equal

Equal checks if this instance equals the target value.

func (FieldMappingEntryStringConfig) Evaluate

Evaluate converts the config to the field mapping instance.

func (FieldMappingEntryStringConfig) EvaluateEnv

func (fm FieldMappingEntryStringConfig) EvaluateEnv() (FieldMapping, error)

EvaluateEnv converts the config to the field mapping instance with environment variables.

func (FieldMappingEntryStringConfig) EvaluateString

EvaluateString converts the config to the field mapping instance.

func (FieldMappingEntryStringConfig) IsZero

func (fm FieldMappingEntryStringConfig) IsZero() bool

IsZero checks if the config is empty.

func (FieldMappingEntryStringConfig) Type

Type returns the type of field mapping config.

type FieldMappingInterface

type FieldMappingInterface interface {
	goutils.IsZeroer

	Type() FieldMappingType
	Evaluate(data any) (any, error)
}

FieldMappingInterface abstracts a field mapping interface.

type FieldMappingObject

type FieldMappingObject struct {
	Properties map[string]FieldMapping `json:"properties" yaml:"properties"`
}

FieldMappingObject is the entry to lookup object values with the specified JMES path.

func (FieldMappingObject) Equal

func (fm FieldMappingObject) Equal(target FieldMappingObject) bool

Equal checks if this instance equals the target value.

func (FieldMappingObject) Evaluate

func (fm FieldMappingObject) Evaluate(data any) (any, error)

Evaluate validates and transforms data with the specified JMES path.

func (FieldMappingObject) IsZero

func (fm FieldMappingObject) IsZero() bool

IsZero checks if the field mapping object is empty.

func (FieldMappingObject) Type

Type returns type of the field mapping entry.

type FieldMappingObjectConfig

type FieldMappingObjectConfig struct {
	// Properties of the field mapping object.
	Properties map[string]FieldMappingConfig `json:"properties" yaml:"properties"`
}

FieldMappingObjectConfig represents configurations for the object field mapping.

func (FieldMappingObjectConfig) Equal

Equal checks if this instance equals the target value.

func (FieldMappingObjectConfig) Evaluate

func (fm FieldMappingObjectConfig) Evaluate(getEnvFunc goenvconf.GetEnvFunc) (FieldMapping, error)

Evaluate converts the config to the field mapping instance.

func (FieldMappingObjectConfig) EvaluateEnv

func (fm FieldMappingObjectConfig) EvaluateEnv() (FieldMapping, error)

EvaluateEnv converts the config to the field mapping instance with environment variables.

func (FieldMappingObjectConfig) IsZero

func (fm FieldMappingObjectConfig) IsZero() bool

IsZero checks if the config is empty.

func (FieldMappingObjectConfig) Type

Type returns the type of field mapping config.

type FieldMappingType

type FieldMappingType string

FieldMappingType represents a field mapping type enum.

const (
	FieldMappingTypeField  FieldMappingType = "field"
	FieldMappingTypeObject FieldMappingType = "object"
)

type JMESTemplateTransformer

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

JMESTemplateTransformer implements the transform template using JMESPath templates.

func NewJMESTemplateTransformer

func NewJMESTemplateTransformer(template FieldMapping) *JMESTemplateTransformer

NewJMESTemplateTransformer creates a new JMESTemplateTransformer instance.

func (JMESTemplateTransformer) Equal

Equal checks if this instance equals the target value.

func (JMESTemplateTransformer) IsZero

func (jtt JMESTemplateTransformer) IsZero() bool

IsZero checks if the JMESTemplateTransformer is empty (zero-valued).

func (JMESTemplateTransformer) Transform

func (jtt JMESTemplateTransformer) Transform(data any) (any, error)

Transform processes and injects data into the template to transform data.

func (JMESTemplateTransformer) Type

Type returns the transform template type of this instance.

type JMESTransformerConfig

type JMESTransformerConfig struct {
	Template FieldMappingConfig `json:"template" yaml:"template"`
}

JMESTransformerConfig represents configurations for the Go template transformer.

func (JMESTransformerConfig) Equal

Equal checks if this instance equals the target value.

func (JMESTransformerConfig) IsZero

func (jt JMESTransformerConfig) IsZero() bool

IsZero checks if the config is empty.

func (JMESTransformerConfig) MarshalJSON

func (jt JMESTransformerConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (JMESTransformerConfig) MarshalYAML

func (jt JMESTransformerConfig) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface.

func (JMESTransformerConfig) Type

Type returns type of the transformer.

func (JMESTransformerConfig) Validate

func (jt JMESTransformerConfig) Validate() error

Validate checks if the config is valid.

Jump to

Keyboard shortcuts

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