converter

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package converter provides utilities for converting between various types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeName added in v0.4.1

func SanitizeName(name string) string

SanitizeName sanitizes a metadata.name field, replacing unsafe characters with _ and truncating if it's longer than 253 characters.

Types

type ContentType added in v0.5.0

type ContentType string

ContentType for conversion.

var (
	// UnknownContent indicates content of unknown type.
	UnknownContent ContentType

	// YAML indicates YAML content.
	YAML ContentType = "yaml"

	// JSON indicates JSON content.
	JSON ContentType = "json"
)

type Decoder added in v0.9.0

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder converts from an object's serialized format to an actual instance of the object. By default, the Decoder does not allow unknown fields.

func FromContentType added in v0.5.0

func FromContentType(ctype string, contents []byte) *Decoder

FromContentType takes an explicit content type to use for creating a conversion Decoder.

func FromFileName added in v0.5.0

func FromFileName(fname string, contents []byte) *Decoder

FromFileName creates a Decoder instance by guessing the type based on the file extension.

func FromJSON added in v0.5.0

func FromJSON(b []byte) *Decoder

FromJSON creates a Decoder instance from a JSON byte array.

func FromJSONString added in v0.5.0

func FromJSONString(s string) *Decoder

FromJSONString creates a Decoder instance from a JSON string.

func FromYAML added in v0.5.0

func FromYAML(b []byte) *Decoder

FromYAML creates a Decoder instance from a YAML byte array.

func FromYAMLString added in v0.5.0

func FromYAMLString(s string) *Decoder

FromYAMLString creates a Decoder instance from a YAML string.

func (*Decoder) AllowUnknownFields added in v0.9.0

func (m *Decoder) AllowUnknownFields(allow bool) *Decoder

AllowUnknownFields indicates whether to allow unknown fields during decoding.

func (*Decoder) ToBundle added in v0.9.0

func (m *Decoder) ToBundle() (*bundle.Bundle, error)

ToBundle converts input data to the Bundle type.

func (*Decoder) ToBundleBuilder added in v0.9.0

func (m *Decoder) ToBundleBuilder() (*bundle.BundleBuilder, error)

ToBundleBuilder converts input data to the BundleBuilder type.

func (*Decoder) ToComponent added in v0.9.0

func (m *Decoder) ToComponent() (*bundle.Component, error)

ToComponent converts input data to the Component type.

func (*Decoder) ToComponentBuilder added in v0.9.0

func (m *Decoder) ToComponentBuilder() (*bundle.ComponentBuilder, error)

ToComponentBuilder converts input data to the ComponentBuilder type.

func (*Decoder) ToComponentSet added in v0.9.0

func (m *Decoder) ToComponentSet() (*bundle.ComponentSet, error)

ToComponentSet converts input data to the ComponentSet type.

func (*Decoder) ToJSONMap added in v0.9.0

func (m *Decoder) ToJSONMap() (map[string]interface{}, error)

ToJSONMap converts from json/yaml data to a map of string-to-interface.

func (*Decoder) ToObject added in v0.9.0

func (m *Decoder) ToObject(obj interface{}) error

ToObject converts to an arbitrary object via standard YAML / JSON serialization.

func (*Decoder) ToUnstructured added in v0.9.0

func (m *Decoder) ToUnstructured() (*unstructured.Unstructured, error)

ToUnstructured converts input data to the Unstructured type.

type Encoder added in v0.9.0

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder converts from an object to some serialized format for the object.

func FromObject added in v0.5.0

func FromObject(obj interface{}) *Encoder

FromObject creates a converting encodeer from an object.

func (*Encoder) ToContentType added in v0.9.0

func (m *Encoder) ToContentType(ctype string) ([]byte, error)

ToContentType converts to a custom content type.

func (*Encoder) ToJSON added in v0.9.0

func (m *Encoder) ToJSON() ([]byte, error)

ToJSON converts an object to JSON bytes slice

func (*Encoder) ToJSONString added in v0.9.0

func (m *Encoder) ToJSONString() (string, error)

ToJSONString converts an object to JSON string

func (*Encoder) ToYAML added in v0.9.0

func (m *Encoder) ToYAML() ([]byte, error)

ToYAML converts an object to YAML bytes slice

func (*Encoder) ToYAMLString added in v0.9.0

func (m *Encoder) ToYAMLString() (string, error)

ToYAMLString converts an object to YAML string

type ObjectExporter

type ObjectExporter struct {
	Objects []*unstructured.Unstructured
}

ObjectExporter exports cluster objects

func (*ObjectExporter) ExportAsMultiYAML

func (e *ObjectExporter) ExportAsMultiYAML() ([]string, error)

ExportAsMultiYAML converts cluster objects into multiple YAML files.

func (*ObjectExporter) ExportAsYAML

func (e *ObjectExporter) ExportAsYAML() (string, error)

ExportAsYAML converts cluster objects into single YAML file.

type UnstructuredConverter added in v0.5.0

type UnstructuredConverter struct {
	// contains filtered or unexported fields
}

UnstructuredConverter is a converter between unstructured.Unstructured and other types.

func FromUnstructured added in v0.5.0

func FromUnstructured(o *unstructured.Unstructured) *UnstructuredConverter

FromUnstructured creates an UnstructuredConverter.

func (*UnstructuredConverter) ExtractObjectMeta added in v0.5.0

func (c *UnstructuredConverter) ExtractObjectMeta() *metav1.ObjectMeta

ExtractObjectMeta creates an ObjectMeta object from an Unstructured object.

func (*UnstructuredConverter) ToObject added in v0.6.1

func (c *UnstructuredConverter) ToObject(obj interface{}) error

ToObject converts an Unstructured object to an arbitrary interface via JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL