コード例 #1
0
ファイル: unstructured.go プロジェクト: Cloven/minikube
func (unstructuredJSONScheme) Encode(obj Object, w io.Writer) error {
	switch t := obj.(type) {
	case *Unstructured:
		return json.NewEncoder(w).Encode(t.Object)
	case *UnstructuredList:
		items := make([]map[string]interface{}, 0, len(t.Items))
		for _, i := range t.Items {
			items = append(items, i.Object)
		}
		t.Object["items"] = items
		defer func() { delete(t.Object, "items") }()
		return json.NewEncoder(w).Encode(t.Object)
	case *Unknown:
		// TODO: Unstructured needs to deal with ContentType.
		_, err := w.Write(t.Raw)
		return err
	default:
		return json.NewEncoder(w).Encode(t)
	}
}
コード例 #2
0
func (unstructuredJSONScheme) EncodeToStream(obj Object, w io.Writer, overrides ...unversioned.GroupVersion) error {
	switch t := obj.(type) {
	case *Unstructured:
		return json.NewEncoder(w).Encode(t.Object)
	case *UnstructuredList:
		var items []map[string]interface{}
		for _, i := range t.Items {
			items = append(items, i.Object)
		}
		t.Object["items"] = items
		defer func() { delete(t.Object, "items") }()
		return json.NewEncoder(w).Encode(t.Object)
	case *Unknown:
		// TODO: Unstructured needs to deal with ContentType.
		_, err := w.Write(t.Raw)
		return err
	default:
		return json.NewEncoder(w).Encode(t)
	}
}
コード例 #3
0
ファイル: unstructured.go プロジェクト: CNDonny/scope
func (unstructuredJSONScheme) EncodeToStream(obj Object, w io.Writer, overrides ...unversioned.GroupVersion) error {
	switch t := obj.(type) {
	case *Unstructured:
		return json.NewEncoder(w).Encode(t.Object)
	case *UnstructuredList:
		type encodeList struct {
			TypeMeta `json:",inline"`
			Items    []map[string]interface{} `json:"items"`
		}
		eList := encodeList{
			TypeMeta: t.TypeMeta,
		}
		for _, i := range t.Items {
			eList.Items = append(eList.Items, i.Object)
		}
		return json.NewEncoder(w).Encode(eList)
	case *Unknown:
		// TODO: Unstructured needs to deal with ContentType.
		_, err := w.Write(t.Raw)
		return err
	default:
		return json.NewEncoder(w).Encode(t)
	}
}