当前位置: 首页>>代码示例>>Golang>>正文


Golang Scope.Meta方法代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/conversion.Scope.Meta方法的典型用法代码示例。如果您正苦于以下问题:Golang Scope.Meta方法的具体用法?Golang Scope.Meta怎么用?Golang Scope.Meta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在k8s/io/kubernetes/pkg/conversion.Scope的用法示例。


在下文中一共展示了Scope.Meta方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Convert_runtime_RawExtension_To_runtime_Object

// Convert_runtime_RawExtension_To_runtime_Object well, this is the reason why there was runtime.Embedded.  The `out` here is hopeless.
// The caller doesn't know the type ahead of time and that means this method can't communicate the return value.  This sucks really badly.
// I'm going to set the `in.Object` field can have callers to this function do magic to pull it back out.  I'm also going to bitch about it.
func Convert_runtime_RawExtension_To_runtime_Object(in *runtime.RawExtension, out runtime.Object, s conversion.Scope) error {
	if in == nil || len(in.Raw) == 0 || in.Object != nil {
		return nil
	}

	// the scheme knows all available group versions, so its possible to build the decoder properly, but it would require some refactoring

	srcVersion, err := unversioned.ParseGroupVersion(s.Meta().SrcVersion)
	if err != nil {
		return err
	}
	decodedObject, err := runtime.Decode(kapi.Codecs.UniversalDecoder(srcVersion), in.Raw)
	if err != nil {
		return err
	}

	internalObject, err := kapi.Scheme.ConvertToVersion(decodedObject, s.Meta().DestVersion)
	if err != nil {
		return err
	}

	in.Object = internalObject

	return nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:conversion.go

示例2: convert_runtime_Object_To_runtime_RawExtension

// Convert_runtime_Object_To_runtime_RawExtension is conversion function that assumes that the runtime.Object you've embedded is in
// the same GroupVersion that your containing type is in.  This is signficantly better than simply breaking.
// Given an ordered list of preferred external versions for a given encode or conversion call, the behavior of this function could be
// made generic, predictable, and controllable.
func convert_runtime_Object_To_runtime_RawExtension(in runtime.Object, out *runtime.RawExtension, s conversion.Scope) error {
	if in == nil {
		return nil
	}

	externalObject, err := internal.Scheme.ConvertToVersion(in, s.Meta().DestVersion)
	if runtime.IsNotRegisteredError(err) {
		switch cast := in.(type) {
		case *runtime.Unknown:
			out.Raw = cast.Raw
			return nil
		case *runtime.Unstructured:
			bytes, err := runtime.Encode(runtime.UnstructuredJSONScheme, externalObject)
			if err != nil {
				return err
			}
			out.Raw = bytes
			return nil
		}
	}
	if err != nil {
		return err
	}

	bytes, err := runtime.Encode(codec, externalObject)
	if err != nil {
		return err
	}

	out.Raw = bytes
	out.Object = externalObject

	return nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:38,代码来源:conversions.go

示例3: Convert_runtime_Object_To_runtime_RawExtension

// Convert_runtime_Object_To_runtime_RawExtension attempts to convert runtime.Objects to the appropriate target, returning an error
// if there is insufficient information on the conversion scope to determine the target version.
func Convert_runtime_Object_To_runtime_RawExtension(c runtime.ObjectConvertor, in *runtime.Object, out *runtime.RawExtension, s conversion.Scope) error {
	if *in == nil {
		return nil
	}
	obj := *in

	switch obj.(type) {
	case *runtime.Unknown, *runtime.Unstructured:
		out.Raw = nil
		out.Object = obj
		return nil
	}

	switch t := s.Meta().Context.(type) {
	case runtime.GroupVersioner:
		converted, err := c.ConvertToVersion(obj, t)
		if err != nil {
			return err
		}
		out.Raw = nil
		out.Object = converted
	default:
		return fmt.Errorf("unrecognized conversion context for versioning: %#v", t)
	}
	return nil
}
开发者ID:legionus,项目名称:origin,代码行数:28,代码来源:extension.go

示例4: convert_runtime_RawExtension_To_runtime_Object

// Convert_runtime_RawExtension_To_runtime_Object well, this is the reason why there was runtime.Embedded.  The `out` here is hopeless.
// The caller doesn't know the type ahead of time and that means this method can't communicate the return value.  This sucks really badly.
// I'm going to set the `in.Object` field can have callers to this function do magic to pull it back out.  I'm also going to bitch about it.
func convert_runtime_RawExtension_To_runtime_Object(in *runtime.RawExtension, out runtime.Object, s conversion.Scope) error {
	if in == nil || len(in.RawJSON) == 0 || in.Object != nil {
		return nil
	}

	decodedObject, err := runtime.Decode(codec, in.RawJSON)
	if err != nil {
		return err
	}

	internalObject, err := internal.Scheme.ConvertToVersion(decodedObject, s.Meta().DestVersion)
	if err != nil {
		return err
	}

	in.Object = internalObject

	return nil
}
开发者ID:rrati,项目名称:origin,代码行数:22,代码来源:conversions.go

示例5: convert_runtime_Object_To_runtime_RawExtension

// Convert_runtime_Object_To_runtime_RawExtension is conversion function that assumes that the runtime.Object you've embedded is in
// the same GroupVersion that your containing type is in.  This is signficantly better than simply breaking.
// Given an ordered list of preferred external versions for a given encode or conversion call, the behavior of this function could be
// made generic, predictable, and controllable.
func convert_runtime_Object_To_runtime_RawExtension(in runtime.Object, out *runtime.RawExtension, s conversion.Scope) error {
	if in == nil {
		return nil
	}

	externalObject, err := internal.Scheme.ConvertToVersion(in, s.Meta().DestVersion)
	if err != nil {
		return err
	}

	bytes, err := runtime.Encode(codec, externalObject)
	if err != nil {
		return err
	}

	out.RawJSON = bytes
	out.Object = externalObject

	return nil
}
开发者ID:rrati,项目名称:origin,代码行数:24,代码来源:conversions.go

示例6: Convert_runtime_Object_To_runtime_RawExtension

// Convert_runtime_Object_To_runtime_RawExtension is conversion function that assumes that the runtime.Object you've embedded is in
// the same GroupVersion that your containing type is in.  This is signficantly better than simply breaking.
// Given an ordered list of preferred external versions for a given encode or conversion call, the behavior of this function could be
// made generic, predictable, and controllable.
func Convert_runtime_Object_To_runtime_RawExtension(in runtime.Object, out *runtime.RawExtension, s conversion.Scope) error {
	if in == nil {
		return nil
	}

	externalObject, err := kapi.Scheme.ConvertToVersion(in, s.Meta().DestVersion)
	if err != nil {
		return err
	}

	targetVersion, err := unversioned.ParseGroupVersion(s.Meta().DestVersion)
	if err != nil {
		return err
	}
	bytes, err := runtime.Encode(kapi.Codecs.LegacyCodec(targetVersion), externalObject)
	if err != nil {
		return err
	}

	out.Raw = bytes
	out.Object = externalObject

	return nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:conversion.go

示例7: Convert_runtime_RawExtension_To_runtime_Object

// Convert_runtime_RawExtension_To_runtime_Object attempts to convert an incoming object into the
// appropriate output type.
func Convert_runtime_RawExtension_To_runtime_Object(c runtime.ObjectConvertor, in *runtime.RawExtension, out *runtime.Object, s conversion.Scope) error {
	if in == nil || in.Object == nil {
		return nil
	}

	switch in.Object.(type) {
	case *runtime.Unknown, *runtime.Unstructured:
		*out = in.Object
		return nil
	}

	switch t := s.Meta().Context.(type) {
	case runtime.GroupVersioner:
		converted, err := c.ConvertToVersion(in.Object, t)
		if err != nil {
			return err
		}
		in.Object = converted
		*out = converted
	default:
		return fmt.Errorf("unrecognized conversion context for conversion to internal: %#v (%T)", t, t)
	}
	return nil
}
开发者ID:legionus,项目名称:origin,代码行数:26,代码来源:extension.go

示例8: fromScope

// fromScope gets the input version, desired output version, and desired Scheme
// from a conversion.Scope.
func (s *Scheme) fromScope(scope conversion.Scope) (inVersion, outVersion string, scheme *Scheme) {
	scheme = s
	inVersion = scope.Meta().SrcVersion
	outVersion = scope.Meta().DestVersion
	return inVersion, outVersion, scheme
}
开发者ID:CNDonny,项目名称:scope,代码行数:8,代码来源:scheme.go


注:本文中的k8s/io/kubernetes/pkg/conversion.Scope.Meta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。