nodeutils

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package nodeutils provides utility methods to perform operations on yaml node

Index

Constants

View Source
const (
	PatchStrategyReplace = "replace"
	PatchStrategyMerge   = "merge"
)
View Source
const (
	NodeTagStr = "!!str"
)

Variables

View Source
var (
	ErrDifferentArgumentsTypes = errors.New("src and dst must be of same type")
	ErrNonPointerArgument      = errors.New("dst must be a pointer")
)
View Source
var (
	ErrNodeNotFound = errors.New("node not found")
)

Functions

func ConvertMapToNode

func ConvertMapToNode(envs map[string]string) (*yaml.Node, error)

ConvertMapToNode converts map[string]string to yaml node

func ConvertNodeToMap

func ConvertNodeToMap(node *yaml.Node) (envs map[string]string, err error)

ConvertNodeToMap converts yaml node to map[string]string

func ConvertNodeToMapInterface

func ConvertNodeToMapInterface(node *yaml.Node) (envs map[string]interface{}, err error)

ConvertNodeToMapInterface converts yaml node to map[string]interface

func CreateMappingNode

func CreateMappingNode(key string) []*yaml.Node

CreateMappingNode creates yaml node based on node key

func CreateNode

func CreateNode(nodeKey Key) []*yaml.Node

CreateNode creates yaml node based on node key Type

func CreateScalarNode

func CreateScalarNode(key, value string) []*yaml.Node

CreateScalarNode creates yaml node based on node key and value

func CreateSequenceNode

func CreateSequenceNode(key string) []*yaml.Node

CreateSequenceNode creates yaml node based on node key

func DeleteNodes

func DeleteNodes(src, dst *yaml.Node, opts ...PatchStrategyOpts) (bool, error)

DeleteNodes delete nodes in dst as per patchStrategy prior performing merge

func Equal

func Equal(node1, node2 *yaml.Node) (bool, error)

Equal checks whether the passed two nodes are equal

func FindNode

func FindNode(node *yaml.Node, opts ...Options) *yaml.Node

FindNode parse the yaml node and return the matched node based on Config Options passed

func GetNodeIndex

func GetNodeIndex(node []*yaml.Node, key string) int

GetNodeIndex retrieves node index of specific node object value; yaml nodes are stored in arrays for all value types. Ex: refer https://pkg.go.dev/gopkg.in/yaml.v3#pkg-overview

func MergeNodes

func MergeNodes(src, dst *yaml.Node) (bool, error)

MergeNodes to merge two yaml nodes src(source) to dst(destination) node

func NotEqual

func NotEqual(node1, node2 *yaml.Node) (bool, error)

NotEqual checks whether the passed two nodes are not deep equal

func UniqNodes

func UniqNodes(nodes []*yaml.Node) []*yaml.Node

Types

type CfgNode

type CfgNode struct {
	ForceCreate bool  // Set to True to create nodes of missing keys. Ex: True for Add/Update operations on yaml node, False for Get/Delete operations on yaml node
	Keys        []Key // keys of config nodes passed in hierarchical order. Ex: [ClientOptions, CLI, DiscoverySources] to get the DiscoverySources node from ClientOptions yaml node
}

CfgNode options to be used to find specific node based on arrays of Keys passed in hierarchical order

type Key

type Key struct {
	Name  string
	Value string
	Type  yaml.Kind
}

type Options

type Options func(config *CfgNode)

func WithForceCreate

func WithForceCreate() Options

func WithKeys

func WithKeys(keys []Key) Options

type PatchStrategyOptions

type PatchStrategyOptions struct {
	Key             string
	PatchStrategies map[string]string
}

type PatchStrategyOpts

type PatchStrategyOpts func(options *PatchStrategyOptions)

func WithPatchStrategies

func WithPatchStrategies(patchStrategies map[string]string) PatchStrategyOpts

func WithPatchStrategyKey

func WithPatchStrategyKey(key string) PatchStrategyOpts

Jump to

Keyboard shortcuts

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