本文整理汇总了Golang中revision/aeip/apigee/net/spatel/k8s-influxdb/influxdb/Godeps/_workspace/src/k8s/io/kubernetes/pkg/conversion.Scope.Convert方法的典型用法代码示例。如果您正苦于以下问题:Golang Scope.Convert方法的具体用法?Golang Scope.Convert怎么用?Golang Scope.Convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类revision/aeip/apigee/net/spatel/k8s-influxdb/influxdb/Godeps/_workspace/src/k8s/io/kubernetes/pkg/conversion.Scope
的用法示例。
在下文中一共展示了Scope.Convert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rawExtensionToEmbeddedObject
// rawExtensionToEmbeddedObject does the conversion you would expect from the name, using the information
// given in conversion.Scope. It's placed in all schemes as a ConversionFunc to enable plugins;
// see the comment for RawExtension.
func (self *Scheme) rawExtensionToEmbeddedObject(in *RawExtension, out *EmbeddedObject, s conversion.Scope) error {
if len(in.RawJSON) == 0 || (len(in.RawJSON) == 4 && string(in.RawJSON) == "null") {
out.Object = nil
return nil
}
// Figure out the type and kind of the output object.
inGroupVersionString, outGroupVersionString, scheme := self.fromScope(s)
dataKind, err := scheme.raw.DataKind(in.RawJSON)
if err != nil {
return err
}
inVersion, err := unversioned.ParseGroupVersion(inGroupVersionString)
if err != nil {
return err
}
outVersion, err := unversioned.ParseGroupVersion(outGroupVersionString)
if err != nil {
return err
}
// We have to make this object ourselves because we don't store the version field for
// plugin objects.
inObj, err := scheme.New(inVersion.WithKind(dataKind.Kind))
if err != nil {
return err
}
err = DecodeInto(scheme, in.RawJSON, inObj)
if err != nil {
return err
}
// Make the desired internal version, and do the conversion.
outObj, err := scheme.New(outVersion.WithKind(dataKind.Kind))
if err != nil {
return err
}
err = scheme.Convert(inObj, outObj)
if err != nil {
return err
}
// Last step, clear the Kind field; that should always be blank in memory.
err = s.Convert(
&emptyPlugin{PluginBase: PluginBase{Kind: ""}},
outObj,
conversion.SourceToDest|conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames,
)
if err != nil {
return err
}
out.Object = outObj
return nil
}
示例2: Convert_v1beta1_RollingUpdateDeployment_To_extensions_RollingUpdateDeployment
func Convert_v1beta1_RollingUpdateDeployment_To_extensions_RollingUpdateDeployment(in *RollingUpdateDeployment, out *extensions.RollingUpdateDeployment, s conversion.Scope) error {
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
defaulting.(func(*RollingUpdateDeployment))(in)
}
if err := s.Convert(in.MaxUnavailable, &out.MaxUnavailable, 0); err != nil {
return err
}
if err := s.Convert(in.MaxSurge, &out.MaxSurge, 0); err != nil {
return err
}
out.MinReadySeconds = int(in.MinReadySeconds)
return nil
}
示例3: embeddedObjectToRawExtension
// embeddedObjectToRawExtension does the conversion you would expect from the name, using the information
// given in conversion.Scope. It's placed in the DefaultScheme as a ConversionFunc to enable plugins;
// see the comment for RawExtension.
func (self *Scheme) embeddedObjectToRawExtension(in *EmbeddedObject, out *RawExtension, s conversion.Scope) error {
if in.Object == nil {
out.RawJSON = []byte("null")
return nil
}
// Figure out the type and kind of the output object.
_, outGroupVersionString, scheme := self.fromScope(s)
objKind, err := scheme.raw.ObjectKind(in.Object)
if err != nil {
return err
}
outVersion, err := unversioned.ParseGroupVersion(outGroupVersionString)
if err != nil {
return err
}
// Manufacture an object of this type and kind.
outObj, err := scheme.New(outVersion.WithKind(objKind.Kind))
if err != nil {
return err
}
// Manually do the conversion.
err = s.Convert(in.Object, outObj, 0)
if err != nil {
return err
}
// Copy the kind field into the output object.
err = s.Convert(
&emptyPlugin{PluginBase: PluginBase{Kind: objKind.Kind}},
outObj,
conversion.SourceToDest|conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames,
)
if err != nil {
return err
}
// Because we provide the correct version, EncodeToVersion will not attempt a conversion.
raw, err := scheme.EncodeToVersion(outObj, outVersion.String())
if err != nil {
// TODO: if this fails, create an Unknown-- maybe some other
// component will understand it.
return err
}
out.RawJSON = raw
return nil
}