modelconv

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLegacyFieldAliases = map[string][]string{
	"targetInfra":          {"targetVmInfra", "vmInfra"},
	"nodeGroups":           {"subGroups", "vm", "vms", "vmGroups"},
	"nodeGroupSize":        {"subGroupSize", "vmGroupSize"},
	"nodeUserName":         {"vmUserName"},
	"nodeUserPassword":     {"vmUserPassword"},
	"targetSpecList":       {"targetVmSpecList"},
	"targetOsImageList":    {"targetVmOsImageList"},
	"targetSpec":           {"targetVmSpec"},
	"targetOsImage":        {"targetVmOsImage"},
	"nodes":                {"servers", "vms", "machines"},
	"sourceRDBMSInstances": {"rdbmsList", "sourceRdbmsList"},
	"targetRDBMSInstances": {"targetRdbmsList"},
	"sourceObjectStorages": {"buckets", "objectStorages"},
	"targetObjectStorages": {"targetBuckets"},
}

DefaultLegacyFieldAliases maps current canonical JSON field names to known legacy field names.

View Source
var DefaultLegacyLabelKeyAliases = map[string]string{
	"sourceMachineId":  "cm-source-machine-ids",
	"sourceMachineIds": "cm-source-machine-ids",
	"sourceGroupId":    "cm-source-group-id",
	"sourceModelId":    "cm-source-model-id",
	"planningModelId":  "cm-planning-model-id",
	"targetModelId":    "cm-target-model-id",
}

DefaultLegacyLabelKeyAliases maps legacy label keys to canonical Cloud-Barista lineage label keys.

View Source
var DefaultLegacyWrapperKeys = []string{
	"onpremiseInfraModel",
	"cloudInfraModel",
	"recommendedInfraModel",
	"recommendedVmInfraModel",
	"sourceObjectStorageModel",
	"recommendedObjectStorageModel",
	"sourceRDBMSModel",
	"recommendedRDBMSModel",
	"sourceNlbModel",
	"dataMigrationModel",
}

DefaultLegacyWrapperKeys lists known single-field wrapper keys used in older envelopes.

Functions

func ConvertAny

func ConvertAny[T any, U any](source T) (U, error)

ConvertAny converts any type T to any type U using JSON marshaling/unmarshaling

func ConvertWithValidation

func ConvertWithValidation[T any, U any](source T) (U, error)

ConvertWithValidation combines type validation and conversion

func ValidateTypeCompatibility

func ValidateTypeCompatibility[T any, U any]() error

ValidateTypeCompatibility checks if two types are compatible for conversion

Types

type ConversionReport added in v0.6.3

type ConversionReport struct {
	TargetSchemaType string           `json:"targetSchemaType" example:"RecommendedInfra"`
	Upcasted         bool             `json:"upcasted" example:"true"`
	MigratedFields   []FieldMigration `json:"migratedFields,omitempty"`
	DroppedFields    []string         `json:"droppedFields,omitempty"`
}

ConversionReport summarizes all schema normalizations performed during reflect upcasting.

func ConvertWithUpcast added in v0.6.3

func ConvertWithUpcast[T any, U any](source T) (U, *ConversionReport, error)

ConvertWithUpcast converts source value T into target struct U with reflect-based legacy field migration.

func UpcastJSON added in v0.6.3

func UpcastJSON(rawJSON []byte, targetType reflect.Type) ([]byte, *ConversionReport, error)

UpcastJSON normalizes raw JSON bytes against targetType using reflect and returns canonical JSON bytes.

func UpcastTo added in v0.6.3

func UpcastTo[T any](rawJSON []byte) (T, *ConversionReport, error)

UpcastTo converts raw JSON bytes into the target Go type T with reflect-based legacy field migration.

type FieldMigration added in v0.6.3

type FieldMigration struct {
	Path string `json:"path" example:"targetVmInfra"`
	From string `json:"from" example:"targetVmInfra"`
	To   string `json:"to" example:"targetInfra"`
}

FieldMigration records a legacy field or key that was mapped to a canonical target field.

Jump to

Keyboard shortcuts

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