fieldpath

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fieldpath provides utilities for working with field paths.

Field paths reference a field within a Kubernetes object via a simple string. API conventions describe the syntax as "standard JavaScript syntax for accessing that field, assuming the JSON object was transformed into a JavaScript object, without the leading dot, such as metadata.name".

Valid examples:

* metadata.name * spec.containers[0].name * data[.config.yml] * metadata.annotations['crossplane.io/external-name'] * spec.items[0][8] * apiVersion * [42]

Invalid examples:

* .metadata.name - Leading period. * metadata..name - Double period. * metadata.name. - Trailing period. * spec.containers[] - Empty brackets. * spec.containers.[0].name - Period before open bracket.

https://github.com/kubernetes/community/blob/61f3d0/contributors/devel/sig-architecture/api-conventions.md#selecting-fields

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the supplied error indicates a field path was not found, for example because a field did not exist within an object or an index was out of bounds in an array.

Types

type Paved

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

A Paved JSON object supports getting and setting values by their field path.

func Pave

func Pave(object map[string]interface{}) *Paved

Pave a JSON object, making it possible to get and set values by field path.

func PaveObject

func PaveObject(o runtime.Object) (*Paved, error)

PaveObject paves a runtime.Object, making it possible to get and set values by field path.

func (*Paved) GetBool

func (p *Paved) GetBool(path string) (bool, error)

GetBool value of the supplied field path.

func (*Paved) GetInteger

func (p *Paved) GetInteger(path string) (int64, error)

GetInteger value of the supplied field path.

func (*Paved) GetNumber

func (p *Paved) GetNumber(path string) (float64, error)

GetNumber value of the supplied field path. Deprecated: Use of float64 is discouraged. Please use GetInteger. See https://github.com/kubernetes/community/blob/c9ae475/contributors/devel/sig-architecture/api-conventions.md#primitive-types

func (*Paved) GetString

func (p *Paved) GetString(path string) (string, error)

GetString value of the supplied field path.

func (*Paved) GetStringArray

func (p *Paved) GetStringArray(path string) ([]string, error)

GetStringArray value of the supplied field path.

func (*Paved) GetStringObject

func (p *Paved) GetStringObject(path string) (map[string]string, error)

GetStringObject value of the supplied field path.

func (*Paved) GetValue

func (p *Paved) GetValue(path string) (interface{}, error)

GetValue of the supplied field path.

func (*Paved) GetValueInto

func (p *Paved) GetValueInto(path string, out interface{}) error

GetValueInto the supplied type.

func (Paved) MarshalJSON

func (p Paved) MarshalJSON() ([]byte, error)

MarshalJSON to the underlying object.

func (*Paved) SetBool

func (p *Paved) SetBool(path string, value bool) error

SetBool value at the supplied field path.

func (*Paved) SetNumber

func (p *Paved) SetNumber(path string, value float64) error

SetNumber value at the supplied field path.

func (*Paved) SetString

func (p *Paved) SetString(path, value string) error

SetString value at the supplied field path.

func (*Paved) SetUnstructuredContent

func (p *Paved) SetUnstructuredContent(content map[string]interface{})

SetUnstructuredContent sets the JSON serialisable content of this Paved.

func (*Paved) SetValue

func (p *Paved) SetValue(path string, value interface{}) error

SetValue at the supplied field path.

func (*Paved) UnmarshalJSON

func (p *Paved) UnmarshalJSON(data []byte) error

UnmarshalJSON from the underlying object.

func (*Paved) UnstructuredContent

func (p *Paved) UnstructuredContent() map[string]interface{}

UnstructuredContent returns the JSON serialisable content of this Paved.

type Segment

type Segment struct {
	Type  SegmentType
	Field string
	Index uint
}

A Segment of a field path.

func Field

func Field(s string) Segment

Field produces a new segment from the supplied string. The segment is always considered to be an object field name.

func FieldOrIndex

func FieldOrIndex(s string) Segment

FieldOrIndex produces a new segment from the supplied string. The segment is considered to be an array index if the string can be interpreted as an unsigned 32 bit integer. Anything else is interpreted as an object field name.

type SegmentType

type SegmentType int

A SegmentType within a field path; either a field within an object, or an index within an array.

const (
	SegmentField SegmentType
	SegmentIndex
)

Segment types.

type Segments

type Segments []Segment

Segments of a field path.

func Parse

func Parse(path string) (Segments, error)

Parse the supplied path into a slice of Segments.

func (Segments) String

func (sg Segments) String() string

Jump to

Keyboard shortcuts

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