valuable

package
v0.0.0-...-f97d723 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(input, output interface{}) (err error)

Decode decodes the given data into the given result. In case of the target Type if a Valuable, we serialize it with `SerializeValuable` func. @param input is the data to decode @param output is the result of the decoding @return an error if the decoding failed

Types

type Valuable

type Valuable struct {
	// Value represents the `value` field of a configuration entry that
	// contains only one value
	Value *string `json:"value,omitempty"`
	// Values represents the `value` field of a configuration entry that
	// contains multiple values stored in a list
	Values []string `json:"values,omitempty"`
	// ValueFrom represents the `valueFrom` field of a configuration entry
	// that contains a reference to a data source
	ValueFrom *ValueFromSource `json:"valueFrom,omitempty"`
}

Valuable represent value who it is possible to retrieve the data in multiple ways. From a simple value without nesting, or from a deep data source.

func SerializeValuable

func SerializeValuable(data interface{}) (*Valuable, error)

SerializeValuable serialize anything to a Valuable @param data is the data to serialize @return the serialized Valuable

func (*Valuable) Contains

func (v *Valuable) Contains(element string) bool

Contains returns true if the Valuable contains the given value @param value is the value to check @return true if the Valuable contains the given value

func (*Valuable) First

func (v *Valuable) First() string

First returns the first value of the Valuable possible values as a string. The order of preference is: - Values - Value - ValueFrom.StaticRef - ValueFrom.EnvRef @return the first value

func (*Valuable) Get

func (v *Valuable) Get() []string

Get returns all values of the Valuable as a slice @return the slice of values

func (*Valuable) Validate

func (v *Valuable) Validate() error

Validate validates the Valuable object and returns an error if any validation fails. In case of envRef, the env variable must exist.

type ValueFromSource

type ValueFromSource struct {
	// StaticRef represents the `staticRef` field of a configuration entry
	// that contains a static value. Can contain a comma separated list
	StaticRef *string `json:"staticRef,omitempty"`
	// EnvRef represents the `envRef` field of a configuration entry
	// that contains a reference to an environment variable
	EnvRef *string `json:"envRef,omitempty"`
}

ValueFromSource represents the `valueFrom` field of a configuration entry that contains a reference to a data source (file, env, etc.)

Jump to

Keyboard shortcuts

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