{"modulePath":"github.com/UnityTech/client-go","version":"v2.0.0+incompatible","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package conversion\n\nPackage conversion provides go object versioning.\n\nSpecifically, conversion provides a way for you to define multiple versions of the same object. You may write functions which implement conversion logic, but for the fields which did not change, copying is automated. This makes it easy to modify the structures you use in memory without affecting the format you store on disk or respond to in your external API calls.\n\n## Variables\n\n```go\nvar DefaultNameFunc = func(t reflect.Type) string { return t.Name() }\n```\n\n## Functions\n\n```go\nfunc Convert_Slice_byte_To_Slice_byte(in *[]byte, out *[]byte, s Scope) error\n```\nConvert\\_Slice\\_byte\\_To\\_Slice\\_byte prevents recursing into every byte\n\n```go\nfunc EnforcePtr(obj interface{}) (reflect.Value, error)\n```\nEnforcePtr ensures that obj is a pointer of some sort. Returns a reflect.Value of the dereferenced pointer, ensuring that it is settable/addressable. Returns an error if this is not possible.\n\n## Types\n\n```go\ntype Cloner struct {\n\t// contains filtered or unexported fields\n}\n```\nCloner knows how to copy one type to another.\n\n```go\nfunc NewCloner() *Cloner\n```\nNewCloner creates a new Cloner object.\n\n```go\nfunc (c *Cloner) DeepCopy(in interface{}) (interface{}, error)\n```\nDeepCopy will perform a deep copy of a given object.\n\n```go\nfunc (c *Cloner) RegisterDeepCopyFunc(deepCopyFunc interface{}) error\n```\nRegisterGeneratedDeepCopyFunc registers a copying func with the Cloner. deepCopyFunc must take three parameters: a type input, a pointer to a type output, and a pointer to Cloner. It should return an error.\n\nExample: c.RegisterGeneratedDeepCopyFunc(\n\n\tfunc(in Pod, out *Pod, c *Cloner) error {\n\t        // deep copy logic...\n\t        return nil\n\t })\n\n```go\nfunc (c *Cloner) RegisterGeneratedDeepCopyFunc(fn GeneratedDeepCopyFunc) error\n```\nSimilar to RegisterDeepCopyFunc, but registers deep copy function that were automatically generated.\n\n```go\ntype ConversionFuncs struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewConversionFuncs() ConversionFuncs\n```\n\n```go\nfunc (c ConversionFuncs) Add(fns ...interface{}) error\n```\nAdd adds the provided conversion functions to the lookup table - they must have the signature \\`func(type1, type2, Scope) error\\`. Functions are added in the order passed and will override previously registered pairs.\n\n```go\nfunc (c ConversionFuncs) Merge(other ConversionFuncs) ConversionFuncs\n```\nMerge returns a new ConversionFuncs that contains all conversions from both other and c, with other conversions taking precedence.\n\n```go\ntype Converter struct {\n\n\t// If non-nil, will be called to print helpful debugging info. Quite verbose.\n\tDebug DebugLogger\n\t// contains filtered or unexported fields\n}\n```\nConverter knows how to convert one type to another.\n\n```go\nfunc NewConverter(nameFn NameFunc) *Converter\n```\nNewConverter creates a new Converter object.\n\n```go\nfunc (c *Converter) AddGenericConversionFunc(fn GenericConversionFunc)\n```\nAddGenericConversionFunc adds a function that accepts the ConversionFunc call pattern (for two conversion types) to the converter. These functions are checked first during a normal conversion, but are otherwise not called. Use AddConversionFuncs when registering typed conversions.\n\n```go\nfunc (c *Converter) ConversionFuncValue(inType, outType reflect.Type) (reflect.Value, bool)\n```\n\n```go\nfunc (c *Converter) Convert(src, dest interface{}, flags FieldMatchingFlags, meta *Meta) error\n```\nConvert will translate src to dest if it knows how. Both must be pointers. If no conversion func is registered and the default copying mechanism doesn't work on this type pair, an error will be returned. Read the comments on the various FieldMatchingFlags constants to understand what the 'flags' parameter does. 'meta' is given to allow you to pass information to conversion functions, it is not used by Convert() other than storing it in the scope. Not safe for objects with cyclic references!\n\n```go\nfunc (c *Converter) DefaultConvert(src, dest interface{}, flags FieldMatchingFlags, meta *Meta) error\n```\nDefaultConvert will translate src to dest if it knows how. Both must be pointers. No conversion func is used. If the default copying mechanism doesn't work on this type pair, an error will be returned. Read the comments on the various FieldMatchingFlags constants to understand what the 'flags' parameter does. 'meta' is given to allow you to pass information to conversion functions, it is not used by DefaultConvert() other than storing it in the scope. Not safe for objects with cyclic references!\n\n```go\nfunc (c *Converter) DefaultMeta(t reflect.Type) (FieldMatchingFlags, *Meta)\n```\nDefaultMeta returns the conversion FieldMappingFunc and meta for a given type.\n\n```go\nfunc (c *Converter) HasConversionFunc(inType, outType reflect.Type) bool\n```\n\n```go\nfunc (c *Converter) IsConversionIgnored(inType, outType reflect.Type) bool\n```\nIsConversionIgnored returns true if the specified objects should be dropped during conversion.\n\n```go\nfunc (c *Converter) RegisterConversionFunc(conversionFunc interface{}) error\n```\nRegisterConversionFunc registers a conversion func with the Converter. conversionFunc must take three parameters: a pointer to the input type, a pointer to the output type, and a conversion.Scope (which should be used if recursive conversion calls are desired).  It must return an error.\n\nExample: c.RegisterConversionFunc(\n\n\tfunc(in *Pod, out *v1.Pod, s Scope) error {\n\t        // conversion logic...\n\t        return nil\n\t })\n\n```go\nfunc (c *Converter) RegisterDefaultingFunc(defaultingFunc interface{}) error\n```\nRegisterDefaultingFunc registers a value-defaulting func with the Converter. defaultingFunc must take one parameter: a pointer to the input type.\n\nExample: c.RegisterDefaultingFunc(\n\n\tfunc(in *v1.Pod) {\n\t        // defaulting logic...\n\t })\n\n```go\nfunc (c *Converter) RegisterGeneratedConversionFunc(conversionFunc interface{}) error\n```\nSimilar to RegisterConversionFunc, but registers conversion function that were automatically generated.\n\n```go\nfunc (c *Converter) RegisterIgnoredConversion(from, to interface{}) error\n```\nRegisterIgnoredConversion registers a \"no-op\" for conversion, where any requested conversion between from and to is ignored.\n\n```go\nfunc (c *Converter) RegisterInputDefaults(in interface{}, fn FieldMappingFunc, defaultFlags FieldMatchingFlags) error\n```\nRegisterInputDefaults registers a field name mapping function, used when converting from maps to structs. Inputs to the conversion methods are checked for this type and a mapping applied automatically if the input matches in. A set of default flags for the input conversion may also be provided, which will be used when no explicit flags are requested.\n\n```go\nfunc (c *Converter) SetStructFieldCopy(srcFieldType interface{}, srcFieldName string, destFieldType interface{}, destFieldName string) error\n```\nSetStructFieldCopy registers a correspondence. Whenever a struct field is encountered which has a type and name matching srcFieldType and srcFieldName, it wil be copied into the field in the destination struct matching destFieldType \u0026 Name, if such a field exists. May be called multiple times, even for the same source field \u0026 type--all applicable copies will be performed.\n\n```go\nfunc (c *Converter) WithConversions(fns ConversionFuncs) *Converter\n```\nWithConversions returns a Converter that is a copy of c but with the additional fns merged on top.\n\n```go\ntype DebugLogger interface {\n\tLogf(format string, args ...interface{})\n}\n```\nDebugLogger allows you to get debugging messages if necessary.\n\n```go\ntype Equalities struct {\n\treflect.Equalities\n}\n```\nThe code for this type must be located in third\\_party, since it forks from go std lib. But for convenience, we expose the type here, too.\n\n```go\nfunc EqualitiesOrDie(funcs ...interface{}) Equalities\n```\nFor convenience, panics on errors\n\n```go\ntype FieldMappingFunc func(key string, sourceTag, destTag reflect.StructTag) (source string, dest string)\n```\nFieldMappingFunc can convert an input field value into different values, depending on the value of the source or destination struct tags.\n\n```go\ntype FieldMatchingFlags int\n```\nFieldMatchingFlags contains a list of ways in which struct fields could be copied. These constants may be | combined.\n\n```go\nconst (\n\t// Loop through destination fields, search for matching source\n\t// field to copy it from. Source fields with no corresponding\n\t// destination field will be ignored. If SourceToDest is\n\t// specified, this flag is ignored. If neither is specified,\n\t// or no flags are passed, this flag is the default.\n\tDestFromSource FieldMatchingFlags = 0\n\t// Loop through source fields, search for matching dest field\n\t// to copy it into. Destination fields with no corresponding\n\t// source field will be ignored.\n\tSourceToDest FieldMatchingFlags = 1 \u003c\u003c iota\n\t// Don't treat it as an error if the corresponding source or\n\t// dest field can't be found.\n\tIgnoreMissingFields\n\t// Don't require type names to match.\n\tAllowDifferentFieldTypeNames\n)\n```\n\n```go\nfunc (f FieldMatchingFlags) IsSet(flag FieldMatchingFlags) bool\n```\nIsSet returns true if the given flag or combination of flags is set.\n\n```go\ntype GeneratedDeepCopyFunc struct {\n\tFn     func(in interface{}, out interface{}, c *Cloner) error\n\tInType reflect.Type\n}\n```\nGeneratedDeepCopyFunc bundles an untyped generated deep-copy function of a type with a reflection type object used as a key to lookup the deep-copy function.\n\n```go\ntype GenericConversionFunc func(a, b interface{}, scope Scope) (bool, error)\n```\n\n```go\ntype Meta struct {\n\t// KeyNameMapping is an optional function which may map the listed key (field name)\n\t// into a source and destination value.\n\tKeyNameMapping FieldMappingFunc\n\t// Context is an optional field that callers may use to pass info to conversion functions.\n\tContext interface{}\n}\n```\nMeta is supplied by Scheme, when it calls Convert.\n\n```go\ntype NameFunc func(t reflect.Type) string\n```\n\n```go\ntype Scope interface {\n\t// Call Convert to convert sub-objects. Note that if you call it with your own exact\n\t// parameters, you'll run out of stack space before anything useful happens.\n\tConvert(src, dest interface{}, flags FieldMatchingFlags) error\n\n\t// DefaultConvert performs the default conversion, without calling a conversion func\n\t// on the current stack frame. This makes it safe to call from a conversion func.\n\tDefaultConvert(src, dest interface{}, flags FieldMatchingFlags) error\n\n\t// If registered, returns a function applying defaults for objects of a given type.\n\t// Used for automatically generating conversion functions.\n\tDefaultingInterface(inType reflect.Type) (interface{}, bool)\n\n\t// SrcTags and DestTags contain the struct tags that src and dest had, respectively.\n\t// If the enclosing object was not a struct, then these will contain no tags, of course.\n\tSrcTag() reflect.StructTag\n\tDestTag() reflect.StructTag\n\n\t// Flags returns the flags with which the conversion was started.\n\tFlags() FieldMatchingFlags\n\n\t// Meta returns any information originally passed to Convert.\n\tMeta() *Meta\n}\n```\nScope is passed to conversion funcs to allow them to continue an ongoing conversion. If multiple converters exist in the system, Scope will allow you to use the correct one from a conversion function--that is, the one your conversion function was called by.\n\n","path":"github.com/UnityTech/client-go/pkg/conversion","name":"conversion","synopsis":"Package conversion provides go object versioning.","isRedistributable":true}
