apimachinery: k8s.io/apimachinery/pkg/conversion Index | Files | Directories

package conversion

import "k8s.io/apimachinery/pkg/conversion"

Package conversion provides go object versioning.

Specifically, 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.

Index

Package Files

converter.go deep_equal.go doc.go helper.go

Variables

var DefaultNameFunc = func(t reflect.Type) string { return t.Name() }

func Convert_Slice_byte_To_Slice_byte Uses

func Convert_Slice_byte_To_Slice_byte(in *[]byte, out *[]byte, s Scope) error

Convert_Slice_byte_To_Slice_byte prevents recursing into every byte

func EnforcePtr Uses

func EnforcePtr(obj interface{}) (reflect.Value, error)

EnforcePtr 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.

type ConversionFunc Uses

type ConversionFunc func(a, b interface{}, scope Scope) error

ConversionFunc converts the object a into the object b, reusing arrays or objects or pointers if necessary. It should return an error if the object cannot be converted or if some data is invalid. If you do not wish a and b to share fields or nested objects, you must copy a before calling this function.

type ConversionFuncs Uses

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

func NewConversionFuncs Uses

func NewConversionFuncs() ConversionFuncs

func (ConversionFuncs) AddUntyped Uses

func (c ConversionFuncs) AddUntyped(a, b interface{}, fn ConversionFunc) error

AddUntyped adds the provided conversion function to the lookup table for the types that are supplied as a and b. a and b must be pointers or an error is returned. This method overwrites previously defined functions.

func (ConversionFuncs) Merge Uses

func (c ConversionFuncs) Merge(other ConversionFuncs) ConversionFuncs

Merge returns a new ConversionFuncs that contains all conversions from both other and c, with other conversions taking precedence.

type Converter Uses

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

Converter knows how to convert one type to another.

func NewConverter Uses

func NewConverter(nameFn NameFunc) *Converter

NewConverter creates a new Converter object.

func (*Converter) Convert Uses

func (c *Converter) Convert(src, dest interface{}, meta *Meta) error

Convert 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. '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!

func (*Converter) DefaultMeta Uses

func (c *Converter) DefaultMeta(t reflect.Type) *Meta

DefaultMeta returns meta for a given type.

func (*Converter) RegisterGeneratedUntypedConversionFunc Uses

func (c *Converter) RegisterGeneratedUntypedConversionFunc(a, b interface{}, fn ConversionFunc) error

RegisterGeneratedUntypedConversionFunc registers a function that converts between a and b by passing objects of those types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce any other guarantee.

func (*Converter) RegisterIgnoredConversion Uses

func (c *Converter) RegisterIgnoredConversion(from, to interface{}) error

RegisterIgnoredConversion registers a "no-op" for conversion, where any requested conversion between from and to is ignored.

func (*Converter) RegisterUntypedConversionFunc Uses

func (c *Converter) RegisterUntypedConversionFunc(a, b interface{}, fn ConversionFunc) error

RegisterUntypedConversionFunc registers a function that converts between a and b by passing objects of those types to the provided function. The function *must* accept objects of a and b - this machinery will not enforce any other guarantee.

func (*Converter) WithConversions Uses

func (c *Converter) WithConversions(fns ConversionFuncs) *Converter

WithConversions returns a Converter that is a copy of c but with the additional fns merged on top.

type Equalities Uses

type Equalities struct {
    reflect.Equalities
}

The 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.

func EqualitiesOrDie Uses

func EqualitiesOrDie(funcs ...interface{}) Equalities

For convenience, panics on errors

type Meta Uses

type Meta struct {
    // Context is an optional field that callers may use to pass info to conversion functions.
    Context interface{}
}

Meta is supplied by Scheme, when it calls Convert.

type NameFunc Uses

type NameFunc func(t reflect.Type) string

type Scope Uses

type Scope interface {
    // Call Convert to convert sub-objects. Note that if you call it with your own exact
    // parameters, you'll run out of stack space before anything useful happens.
    Convert(src, dest interface{}) error

    // Meta returns any information originally passed to Convert.
    Meta() *Meta
}

Scope 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.

Directories

PathSynopsis
queryparamsPackage queryparams provides conversion from versioned runtime objects to URL query values

Package conversion imports 3 packages (graph) and is imported by 558 packages. Updated 2020-11-03. Refresh now. Tools for package owners.