本文整理匯總了Golang中k8s/io/kubernetes/pkg/runtime.RawExtension.RawJSON方法的典型用法代碼示例。如果您正苦於以下問題:Golang RawExtension.RawJSON方法的具體用法?Golang RawExtension.RawJSON怎麽用?Golang RawExtension.RawJSON使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/runtime.RawExtension
的用法示例。
在下文中一共展示了RawExtension.RawJSON方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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.RawJSON = cast.RawJSON
return nil
case *runtime.Unstructured:
bytes, err := runtime.Encode(runtime.UnstructuredJSONScheme, externalObject)
if err != nil {
return err
}
out.RawJSON = bytes
return nil
}
}
if err != nil {
return err
}
bytes, err := runtime.Encode(codec, externalObject)
if err != nil {
return err
}
out.RawJSON = bytes
out.Object = externalObject
return nil
}
示例2: Visit
// Visit implements Visitor over a stream. StreamVisitor is able to distinct multiple resources in one stream.
func (v *StreamVisitor) Visit(fn VisitorFunc) error {
d := yaml.NewYAMLOrJSONDecoder(v.Reader, 4096)
for {
ext := runtime.RawExtension{}
if err := d.Decode(&ext); err != nil {
if err == io.EOF {
return nil
}
return err
}
ext.RawJSON = bytes.TrimSpace(ext.RawJSON)
if len(ext.RawJSON) == 0 || bytes.Equal(ext.RawJSON, []byte("null")) {
continue
}
if err := ValidateSchema(ext.RawJSON, v.Schema); err != nil {
return fmt.Errorf("error validating %q: %v", v.Source, err)
}
info, err := v.InfoForData(ext.RawJSON, v.Source)
if err != nil {
if fnErr := fn(info, err); fnErr != nil {
return fnErr
}
continue
}
if err := fn(info, nil); err != nil {
return err
}
}
}
示例3: Visit
// Visit implements Visitor over a stream. StreamVisitor is able to distinct multiple resources in one stream.
func (v *StreamVisitor) Visit(fn VisitorFunc) error {
d := yaml.NewYAMLOrJSONDecoder(v.Reader, 4096)
for {
ext := runtime.RawExtension{}
if err := d.Decode(&ext); err != nil {
if err == io.EOF {
return nil
}
return err
}
ext.RawJSON = bytes.TrimSpace(ext.RawJSON)
if len(ext.RawJSON) == 0 || bytes.Equal(ext.RawJSON, []byte("null")) {
continue
}
if err := ValidateSchema(ext.RawJSON, v.Schema); err != nil {
return fmt.Errorf("error validating %q: %v", v.Source, err)
}
info, err := v.InfoForData(ext.RawJSON, v.Source)
if err != nil {
if v.IgnoreErrors {
fmt.Fprintf(os.Stderr, "error: could not read an encoded object: %v\n", err)
glog.V(4).Infof("Unreadable: %s", string(ext.RawJSON))
continue
}
return err
}
if err := fn(info); err != nil {
return err
}
}
}
示例4: 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
}
示例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 := 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.RawJSON = bytes
out.Object = externalObject
return nil
}