keyval

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 4 Imported by: 0

README

keyval

Manipulate arbitrary key/value data from JSON/YAML sources

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitKey

func SplitKey(key string, delim ...string) []string

SplitKey splits a multi-part key string into its separate components. The default delimiter is "."

Types

type KeyVal

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

func New added in v0.1.5

func New() *KeyVal

New returns an empty KeyVal instance

func NewFromJson

func NewFromJson(data []byte) (*KeyVal, error)

NewFromJson returns a new KeyVal instance from a JSON source

func NewFromMap

func NewFromMap(data map[string]any) *KeyVal

NewFromMap returns a new KeyVal instance from a map[string]any

func NewFromYaml

func NewFromYaml(data []byte) (*KeyVal, error)

NewFromJson returns a new KeyVal instance from a YAML source

func (*KeyVal) Array

func (kv *KeyVal) Array(keys ...string) ([]any, error)

Array returns an array or an error if the data can't be found, or properly cast

func (*KeyVal) Boolean

func (kv *KeyVal) Boolean(keys ...string) (bool, error)

Boolean returns a boolean or an error if the data can't be found, or properly cast

func (*KeyVal) Copy

func (kv *KeyVal) Copy() *KeyVal

Copy returns a deep copy of KeyVal

func (*KeyVal) CreateValue added in v0.1.4

func (kv *KeyVal) CreateValue(value any, keys ...string) error

CreateValue sets a nested value within the object. If a parent key cannot be located, it is created. Key collisions are ignored.

func (*KeyVal) GetKeyVal added in v0.1.7

func (kv *KeyVal) GetKeyVal(keys ...string) (*KeyVal, error)

GetKeyVal returns a new KeyVal object at the nested key position.

func (*KeyVal) Mapping

func (kv *KeyVal) Mapping(keys ...string) (map[string]any, error)

Mapping returns an array or an error if the data can't be found, or properly cast

func (*KeyVal) Number

func (kv *KeyVal) Number(keys ...string) (float64, error)

Number returns a float or an error if the data can't be found, or properly cast

func (*KeyVal) SetValue

func (kv *KeyVal) SetValue(value any, keys ...string) error

SetValue sets a nested value within the object. If a parent key cannot be located, an error is returned.

func (*KeyVal) Stack

func (kv *KeyVal) Stack(layer *KeyVal) *KeyVal

Stack creates a new KeyVal object with the current instance being the base, and layer being stacked atop

func (*KeyVal) String

func (kv *KeyVal) String(keys ...string) (string, error)

String returns a string or an error if the data can't be found, or properly cast

func (*KeyVal) ToJson added in v0.1.6

func (kv *KeyVal) ToJson() ([]byte, error)

ToJson marshals the entire data structure to a JSON byte array

func (*KeyVal) ToYaml added in v0.1.6

func (kv *KeyVal) ToYaml() ([]byte, error)

ToYaml marshals the entire data structure to a YAML byte array

func (*KeyVal) Value

func (kv *KeyVal) Value(keys ...string) (any, error)

Value returns a value or an error if the value cannot be located

Jump to

Keyboard shortcuts

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