meta

package
v1.1.35 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnmarshalNonStringFieldsFromJSON

func UnmarshalNonStringFieldsFromJSON() mapstructure.DecodeHookFunc

Types

type Decoder

type Decoder[T any] struct {
	// Prefix optional prefix to add to keys when serializing. eg. "whatever.terra.bio/"
	Prefix string
	// TagName struct tag (default "key")
	TagName string
}

Decoder can decode a simple struct into a map[string]string for use of Kubernetes annotations and labels. It also supports decoding a map[string]string back into a struct. Note that string fields are added to the map as-is; all other field types are encoded/decoded into a JSON string.

Structs with pointer fields are not supported. This has been tested for numeric, bool, and string datatypes; other data types might not work. (For example, runes definitely do not work because they are not supported by mapstructure).

func (Decoder[T]) FromMap

func (d Decoder[T]) FromMap(m map[string]string) (*T, error)

func (Decoder[T]) MergeTo

func (d Decoder[T]) MergeTo(s T, m map[string]string) error

func (Decoder[T]) ToMap

func (d Decoder[T]) ToMap(s T) (map[string]string, error)

Jump to

Keyboard shortcuts

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