mapbuilder

package
v2.40.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger *logger.Logger

Functions

This section is empty.

Types

type IteratorReference

type IteratorReference struct {
	Path  string
	Value iterator.Iterator
}

type LocalVariable added in v2.32.0

type LocalVariable struct {
	Name  string
	Value any
}

type MapBuilder

type MapBuilder struct {
	BodyRaw []byte

	TemplateIterator      iterator.Iterator
	TemplateIteratorNames []string

	// Array output settings
	ArraySize   int
	ArrayPrefix string
	ArraySuffix string
	// contains filtered or unexported fields
}

MapBuilder creates body builder

func NewInitializedMapBuilder

func NewInitializedMapBuilder(initBody bool) *MapBuilder

NewInitializedMapBuilder creates a new map builder with the map set to an empty map

func NewMapBuilder

func NewMapBuilder() *MapBuilder

NewMapBuilder creates a new map builder with the map set to nil

func NewMapBuilderFromJSON

func NewMapBuilderFromJSON(data string) (*MapBuilder, error)

NewMapBuilderFromJSON returns a new mapper builder object created from json

func NewMapBuilderFromJsonnetSnippet

func NewMapBuilderFromJsonnetSnippet(snippet string) (*MapBuilder, error)

NewMapBuilderFromJsonnetSnippet returns a new mapper builder from a jsonnet snippet See https://jsonnet.org/learning/tutorial.html for details on how to create a snippet

func NewMapBuilderWithInit

func NewMapBuilderWithInit(body []byte) *MapBuilder

NewMapBuilderWithInit returns a new map builder seeding the builder with json

func (*MapBuilder) AddLocalTemplateVariable added in v2.32.0

func (b *MapBuilder) AddLocalTemplateVariable(name string, value any) error

AddLocalTemplateVariable will inject new local variables into the jsonnet template using the local name = value; syntax. It allows users to access additional variables more easily

func (*MapBuilder) AppendTemplate

func (b *MapBuilder) AppendTemplate(template string) *MapBuilder

AppendTemplate appends a templates to be merged in with the body

func (*MapBuilder) ApplyMap

func (b *MapBuilder) ApplyMap(body map[string]interface{})

ApplyMap sets a new map to the body. This will remove any existing values in the body

func (*MapBuilder) ApplyTemplates

func (b *MapBuilder) ApplyTemplates(existingJSON []byte, input []byte, appendTemplates bool) ([]byte, error)

ApplyTemplates merges the existing body data with a given jsonnet snippet. When reverse is false, then the snippet will be applied to the existing data, when reverse is true, then the given snippet will be the base, and the existing data will be applied to the new snippet.

func (*MapBuilder) ClearMap

func (b *MapBuilder) ClearMap()

ClearMap removed the existing map and sets it to nil.

func (*MapBuilder) Get

func (b *MapBuilder) Get(key string) interface{}

Get returns a value as an interface

func (*MapBuilder) GetBody

func (b *MapBuilder) GetBody() (interface{}, error)

GetBody returns the body as an interface

func (*MapBuilder) GetFile

func (b *MapBuilder) GetFile() (*os.File, error)

GetFile get the file reference

func (*MapBuilder) GetFileContents

func (b *MapBuilder) GetFileContents() *os.File

GetFileContents returns the map contents as a file (only if a file is already set)

func (*MapBuilder) GetMap

func (b *MapBuilder) GetMap() map[string]interface{}

GetMap returns the body as a map[string]interface{}

func (*MapBuilder) GetRaw

func (b *MapBuilder) GetRaw() string

GetRaw get raw body

func (*MapBuilder) GetString

func (b *MapBuilder) GetString(key string) (string, bool)

GetString the value as a string

func (*MapBuilder) HasChanged

func (b *MapBuilder) HasChanged() bool

func (*MapBuilder) HasFile

func (b *MapBuilder) HasFile() bool

HasFile return true if the body is being set from file

func (*MapBuilder) HasRaw

func (b *MapBuilder) HasRaw() bool

HasRaw return true if the body is being set from raw data

func (*MapBuilder) KeyExists

func (b *MapBuilder) KeyExists(path string) bool

KeyExists return true if the given dot notation path exists or not

func (*MapBuilder) MarshalJSON

func (b *MapBuilder) MarshalJSON() (body []byte, err error)

func (*MapBuilder) MarshalJSONArray

func (b *MapBuilder) MarshalJSONArray() ([]byte, error)

func (*MapBuilder) MarshalJSONObject

func (b *MapBuilder) MarshalJSONObject() (body []byte, err error)

MarshalJSON returns the body as json

func (*MapBuilder) MarshalJSONWithInput

func (b *MapBuilder) MarshalJSONWithInput(input interface{}) (body []byte, err error)

MarshalJSONWithInput convers the body to json and also injecting additional data into the template input to make it available using the input.value variable in jsonnet

func (*MapBuilder) MergeJSON

func (b *MapBuilder) MergeJSON(existingJSON []byte, maps ...map[string]interface{}) ([]byte, error)

func (*MapBuilder) MergeMaps

func (b *MapBuilder) MergeMaps(maps ...map[string]interface{}) error

MergeMaps merges a list of maps into the body. If the body does not already exists, then it will be ignored. Only shallow merging is done. Duplicate keys will be overwritten by maps later in the list

func (*MapBuilder) PrependTemplate

func (b *MapBuilder) PrependTemplate(template string) *MapBuilder

PrependTemplate prepends a templates to be merged in with the body

func (*MapBuilder) Set

func (b *MapBuilder) Set(path string, value interface{}) error

Set sets a value to a give dot notation path

func (*MapBuilder) SetAppendTemplatePreference added in v2.40.0

func (b *MapBuilder) SetAppendTemplatePreference(value bool) *MapBuilder

SetAppendTemplatePreference sets if the templates should be appended when evaluating the entire map Setting it to append means that the template can override other values provided in the map

func (*MapBuilder) SetApplyTemplateOnMarshalPreference

func (b *MapBuilder) SetApplyTemplateOnMarshalPreference(value bool) *MapBuilder

SetApplyTemplateOnMarshalPreference sets whether the templates should be applied during marshalling or not.

func (*MapBuilder) SetEmptyMap

func (b *MapBuilder) SetEmptyMap() *MapBuilder

SetEmptyMap sets the body to an empty map. It will override an existing body

func (*MapBuilder) SetFile

func (b *MapBuilder) SetFile(path string)

SetFile sets the body to the contents of the file path

func (*MapBuilder) SetMap

func (b *MapBuilder) SetMap(body map[string]interface{})

SetMap sets a new map to the body (if not nil). This will remove any existing values in the body

func (*MapBuilder) SetOptionalMap

func (b *MapBuilder) SetOptionalMap(value map[string]interface{})

SetOptionalMap set optional map values which can be overwritten by other values

func (*MapBuilder) SetPath

func (b *MapBuilder) SetPath(path string, value interface{}) error

func (*MapBuilder) SetRaw

func (b *MapBuilder) SetRaw(v string)

SetRaw sets the body to a raw string

func (*MapBuilder) SetRawPath

func (b *MapBuilder) SetRawPath(path string, value []byte) error

func (*MapBuilder) SetRequiredKeys

func (b *MapBuilder) SetRequiredKeys(keys ...string)

SetRequiredKeys stores the list of keys which should be present when marshaling the map to json. Nested paths are accepted via dot notation

func (*MapBuilder) SetTemplateVariables

func (b *MapBuilder) SetTemplateVariables(variables map[string]interface{})

SetTemplateVariables stores the given variables that will be used in the template evaluation

Jump to

Keyboard shortcuts

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