types

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package types contains all of the type metadata for entities output by chronoctl

Index

Constants

This section is empty.

Variables

View Source
var Registry = make(ObjectRegistry)

Registry contains the type information for all objects in the Chronosphere API.

Functions

func Description

func Description(typeKind string, idKeyPairs ...string) string

Description creates a friendly identifying description of an object based on its king and a list of key-value pairs. The idKeyPairs must have an even number of elements, although values can be empty. Example: TypeDescription("Foo") will result in "Foo{}" Example: TypeDescription("Foo", "id", "xyz", "name", "thing") will result in "Foo{id="xyz", name="thing"}" Example: TypeDescription("Foo", "id", "", "name", "thing") will result in "Foo{name="thing"}"

func DisplayName

func DisplayName(typeKind string, identifier string) string

DisplayName creates a name for a type based on its metadata.

func EncodeYAML

func EncodeYAML(v interface{}) ([]byte, error)

EncodeYAML marshals an object as YAML.

func MustDecodeSingleObject

func MustDecodeSingleObject[T Object](r io.Reader, permissiveParsing bool) (T, error)

MustDecodeSingleObject reads a single object and returns an error if there are more than one object in the input stream.

func MustRegisterObject

func MustRegisterObject(meta TypeMeta, obj Object)

MustRegisterObject registers a Chronosphere object. `meta` must define the object's Kind and API version, be a pointer to a struct, and there must not be a different object with the same Kind and API version in Registry already. If any of these conditions aren't met the function will panic. MustRegisterObject is intended to be called in init functions to register all valid types at startup.

func TypeDescription

func TypeDescription(obj Object, idKeyPairs ...string) string

TypeDescription creates a friendly identifying description of an object based on its king and a list of key-value pairs. See Description for examples.

func WrongObjectErr

func WrongObjectErr(want, actual Object) error

WrongObjectErr returns an error indicating that the object the CLI is formatting is not what was expected.

Types

type Object

type Object interface {
	Type() TypeMeta
	Description() string
	Identifier() string
}

Object is the interface that all types in the Chronosphere API must fulfill.

func Decode

func Decode(r io.Reader, permissiveParsing bool) ([]Object, error)

Decode decodes objects from `r` until it encounters an EOF. It uses the API registry to discover the types of the objects it decodes.

type ObjectRegistry

type ObjectRegistry map[TypeMeta]reflect.Type

ObjectRegistry is a map from the type information of an object to it's actual Go type.

type TypeMeta

type TypeMeta struct {
	// APIVersion is the versioned schema of this representation of an object.
	APIVersion string `json:"api_version,omitempty"`

	// Kind is the name of the resource this object represents in the Chronosphere API.
	Kind string `json:"kind,omitempty"`
}

TypeMeta describes an object in the Chronosphere API. Note that the json tags for the object use snake case instead of camel case for field names to match the convention used by the API.

func (TypeMeta) String

func (t TypeMeta) String() string

String returns a string representation of the type metadata.

func (TypeMeta) Type

func (t TypeMeta) Type() TypeMeta

Type returns itself

Jump to

Keyboard shortcuts

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