Documentation ¶
Index ¶
- Constants
- func MergeP(tr Translator, tm TranslationSet, r *report.Report, prefix interface{}, ...)
- func MergeP2(tr Translator, tm TranslationSet, r *report.Report, fromPrefix interface{}, ...)
- func PrefixReport(r report.Report, prefix interface{}) report.Report
- type Translation
- type TranslationSet
- func (ts TranslationSet) AddFromCommonObject(fromPrefix path.ContextPath, toPrefix path.ContextPath, to interface{})
- func (ts TranslationSet) AddFromCommonSource(common path.ContextPath, toPrefix path.ContextPath, to interface{})
- func (ts TranslationSet) AddTranslation(from, to path.ContextPath)
- func (ts TranslationSet) DebugVerifyCoverage(v interface{}) error
- func (ts TranslationSet) Descend(to path.ContextPath) TranslationSet
- func (ts TranslationSet) Map(mappings TranslationSet) TranslationSet
- func (ts TranslationSet) Merge(from TranslationSet)
- func (ts TranslationSet) MergeP(prefix interface{}, from TranslationSet)
- func (ts TranslationSet) MergeP2(fromPrefix interface{}, toPrefix interface{}, from TranslationSet)
- func (ts TranslationSet) Prefix(prefix interface{}) TranslationSet
- func (ts TranslationSet) PrefixPaths(fromPrefix, toPrefix path.ContextPath) TranslationSet
- func (ts TranslationSet) String() string
- type Translator
Constants ¶
const ( TAG_KEY = "butane" TAG_AUTO_SKIP = "auto_skip" )
Variables ¶
This section is empty.
Functions ¶
func MergeP ¶
func MergeP(tr Translator, tm TranslationSet, r *report.Report, prefix interface{}, from interface{}, to interface{})
Utility function to run a translation and merge the result, with the specified prefix, into the specified TranslationSet and Report.
func MergeP2 ¶
func MergeP2(tr Translator, tm TranslationSet, r *report.Report, fromPrefix interface{}, from interface{}, toPrefix interface{}, to interface{})
Utility function to run a translation and merge the result, with the specified prefixes, into the specified TranslationSet and Report.
Types ¶
type Translation ¶
type Translation struct { From path.ContextPath To path.ContextPath }
Translation represents how a path changes when translating. If something at $yaml.storage.filesystems.4 generates content at $json.systemd.units.3 a translation can represent that. This allows validation errors in Ignition structs to be tracked back to their source in the yaml.
func (Translation) String ¶
func (t Translation) String() string
type TranslationSet ¶
type TranslationSet struct { FromTag string ToTag string Set map[string]Translation }
TranslationSet represents all of the translations that occurred. They're stored in a map from a string representation of the destination path to the translation struct. The map is purely an optimization to allow fast lookups. Ideally the map would just be from the destination path.ContextPath to the source path.ContextPath, but ContextPath contains a slice which are not comparable and thus cannot be used as keys in maps.
func NewTranslationSet ¶
func NewTranslationSet(fromTag, toTag string) TranslationSet
func Prefixed ¶
func Prefixed(tr Translator, prefix interface{}, from interface{}, to interface{}) (TranslationSet, report.Report)
Utility function to run a translation and prefix the resulting TranslationSet and Report.
func (TranslationSet) AddFromCommonObject ¶ added in v0.15.0
func (ts TranslationSet) AddFromCommonObject(fromPrefix path.ContextPath, toPrefix path.ContextPath, to interface{})
AddFromCommonObject adds translations for all of the paths in to. The paths being translated are prefixed by fromPrefix and the translated paths are prefixed by toPrefix. This is useful when we want to copy all the fields of an object to another with the same field names.
func (TranslationSet) AddFromCommonSource ¶
func (ts TranslationSet) AddFromCommonSource(common path.ContextPath, toPrefix path.ContextPath, to interface{})
AddFromCommonSource adds translations for all of the paths in to from a single common path. This is useful if one part of a config generates a large struct and all of the large struct should map to one path in the config being translated.
func (TranslationSet) AddTranslation ¶
func (ts TranslationSet) AddTranslation(from, to path.ContextPath)
AddTranslation adds a translation to the set
func (TranslationSet) DebugVerifyCoverage ¶
func (ts TranslationSet) DebugVerifyCoverage(v interface{}) error
DebugVerifyCoverage recursively checks whether every non-zero field in v has a translation. If translations are missing, it returns a multi-line error listing them.
func (TranslationSet) Descend ¶
func (ts TranslationSet) Descend(to path.ContextPath) TranslationSet
Descend returns the subtree of translations rooted at the specified To path.
func (TranslationSet) Map ¶ added in v0.15.0
func (ts TranslationSet) Map(mappings TranslationSet) TranslationSet
Map returns a new TranslationSet with To translation paths further translated through mappings. Translations not listed in mappings are copied unmodified.
func (TranslationSet) Merge ¶
func (ts TranslationSet) Merge(from TranslationSet)
Merge adds all the entries to the set. It mutates the Set in place.
func (TranslationSet) MergeP ¶
func (ts TranslationSet) MergeP(prefix interface{}, from TranslationSet)
MergeP is like Merge, but it adds a prefix to the set being merged in.
func (TranslationSet) MergeP2 ¶
func (ts TranslationSet) MergeP2(fromPrefix interface{}, toPrefix interface{}, from TranslationSet)
MergeP2 is like Merge, but it adds distinct prefixes to each side of the set being merged in.
func (TranslationSet) Prefix ¶
func (ts TranslationSet) Prefix(prefix interface{}) TranslationSet
Prefix returns a TranslationSet with all translation paths prefixed by prefix.
func (TranslationSet) PrefixPaths ¶
func (ts TranslationSet) PrefixPaths(fromPrefix, toPrefix path.ContextPath) TranslationSet
PrefixPaths returns a TranslationSet with from translation paths prefixed by fromPrefix and to translation paths prefixed by toPrefix.
func (TranslationSet) String ¶
func (ts TranslationSet) String() string
type Translator ¶
type Translator interface { // Adds a custom translator for cases where the structs are not identical. Must be of type // func(fromType, optionsType) -> (toType, TranslationSet, report.Report). // The translator should return the set of all translations it did. AddCustomTranslator(t interface{}) // Also returns a list of source and dest paths, autocompleted by fromTag and toTag Translate(from, to interface{}) (TranslationSet, report.Report) }
func NewTranslator ¶
func NewTranslator(fromTag, toTag string, options interface{}) Translator
NewTranslator creates a new Translator for translating from types with fromTag struct tags (e.g. "yaml") to types with toTag struct tages (e.g. "json"). These tags are used when determining paths when generating the TranslationSet returned by Translator.Translate()