當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Decoder.Decode方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/runtime.Decoder.Decode方法的典型用法代碼示例。如果您正苦於以下問題:Golang Decoder.Decode方法的具體用法?Golang Decoder.Decode怎麽用?Golang Decoder.Decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/runtime.Decoder的用法示例。


在下文中一共展示了Decoder.Decode方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SortObjects

func SortObjects(decoder runtime.Decoder, objs []runtime.Object, fieldInput string) (*RuntimeSort, error) {
	parser := jsonpath.New("sorting")

	field, err := massageJSONPath(fieldInput)
	if err != nil {
		return nil, err
	}

	if err := parser.Parse(field); err != nil {
		return nil, err
	}

	for ix := range objs {
		item := objs[ix]
		switch u := item.(type) {
		case *runtime.Unknown:
			var err error
			if objs[ix], _, err = decoder.Decode(u.Raw, nil, nil); err != nil {
				return nil, err
			}
		}
	}

	values, err := parser.FindResults(reflect.ValueOf(objs[0]).Elem().Interface())
	if err != nil {
		return nil, err
	}
	if len(values) == 0 {
		return nil, fmt.Errorf("couldn't find any field with path: %s", field)
	}

	sorter := NewRuntimeSort(field, objs)
	sort.Sort(sorter)
	return sorter, nil
}
開發者ID:CodeJuan,項目名稱:kubernetes,代碼行數:35,代碼來源:sorting_printer.go

示例2: DecodeNestedRawExtensionOrUnknown

// DecodeNestedRawExtensionOrUnknown
func DecodeNestedRawExtensionOrUnknown(d runtime.Decoder, ext *runtime.RawExtension) {
	if ext.Raw == nil || ext.Object != nil {
		return
	}
	obj, gvk, err := d.Decode(ext.Raw, nil, nil)
	if err != nil {
		// TODO: record mime-type with the object
		unk := &runtime.Unknown{Raw: ext.Raw}
		if gvk != nil {
			unk.APIVersion = gvk.GroupVersion().String()
			unk.Kind = gvk.Kind
		}
		obj = unk
	}
	ext.Object = obj
}
開發者ID:legionus,項目名稱:origin,代碼行數:17,代碼來源:extension.go

示例3: AddObjectsFromPath

// AddObjectsFromPath loads the JSON or YAML file containing Kubernetes API resources
// and adds them to the provided ObjectRetriever.
func AddObjectsFromPath(path string, o ObjectRetriever, decoder runtime.Decoder) error {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return err
	}
	data, err = yaml.ToJSON(data)
	if err != nil {
		return err
	}
	obj, err := decoder.Decode(data)
	if err != nil {
		return err
	}
	if err := o.Add(obj); err != nil {
		return err
	}
	return nil
}
開發者ID:naxhh,項目名稱:heapster,代碼行數:20,代碼來源:fixture.go

示例4: SortObjects

func SortObjects(decoder runtime.Decoder, objs []runtime.Object, fieldInput string) (*RuntimeSort, error) {
	parser := jsonpath.New("sorting")

	field, err := massageJSONPath(fieldInput)
	if err != nil {
		return nil, err
	}

	if err := parser.Parse(field); err != nil {
		return nil, err
	}

	for ix := range objs {
		item := objs[ix]
		switch u := item.(type) {
		case *runtime.Unknown:
			var err error
			// decode runtime.Unknown to runtime.Unstructured for sorting.
			// we don't actually want the internal versions of known types.
			if objs[ix], _, err = decoder.Decode(u.Raw, nil, &unstructured.Unstructured{}); err != nil {
				return nil, err
			}
		}
	}

	var values [][]reflect.Value
	if unstructured, ok := objs[0].(*unstructured.Unstructured); ok {
		values, err = parser.FindResults(unstructured.Object)
	} else {
		values, err = parser.FindResults(reflect.ValueOf(objs[0]).Elem().Interface())
	}

	if err != nil {
		return nil, err
	}
	if len(values) == 0 {
		return nil, fmt.Errorf("couldn't find any field with path: %s", field)
	}

	sorter := NewRuntimeSort(field, objs)
	sort.Sort(sorter)
	return sorter, nil
}
開發者ID:nak3,項目名稱:kubernetes,代碼行數:43,代碼來源:sorting_printer.go


注:本文中的k8s/io/kubernetes/pkg/runtime.Decoder.Decode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。