envmap

package
v0.0.0-...-14ae695 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LabelCleaner

func LabelCleaner(str string) string

func ReplaceEnvVariables

func ReplaceEnvVariables(inBytes []byte, valuesMap map[string]string) []byte

ReplaceEnvVariables will search a blob of data for the pattern `${FOO:bar}`, where `FOO` is an environment variable name and `bar` is a default value. The `bar` section (including the colon) can be left out if there is no appropriate default value for the field.

For each aforementioned pattern found in the blob the contents of the respective environment variable will be read and will replace the pattern. If the environment variable is empty or does not exist then either the default value is used or the field will be left empty.

This is copied version from: https://github.com/benthosdev/benthos/blob/0c6a2e570999be7539926cb463d31fe92e166c72/internal/config/env_vars.go#L24

Types

type Kind

type Kind int
const (
	KindString Kind
	KindArray
)

func IsEnvVarString

func IsEnvVarString(ctx context.Context, str string) (key string, kind Kind, err error)

IsEnvVarString return whether the str contains regex ${KEY} or ${KEY:[]}. If str is using that value, then it will be considered as environment variable, and we must treat it like as is it.

If the format matched, we will return the KEY name to get the exact value from environment variable map.

String will be valid as environment variable if this requirements is meet: 1. Prefix "${" and Suffix "}" 2. Only utf8 characters 3. Must not start with number character 4. Must only contain uppercase letter and _. 5. For type array, the suffix can be (and must be) ":[]}" I.e: ${KAFKA_BROKERS} = KAFKA_BROKERS, string, nil ${KAFKA_BROKERS:[]} = KAFKA_BROKERS, array, nil ${KAFKA_BROKERS[]} = empty string, unknown, error

type StrOrArr

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

func MapValue

func MapValue(ctx context.Context, s *StrOrArr, values map[string]string) (mapped *StrOrArr, err error)

MapValue will return new copied StrOrArr but will replace all string with format ${} with the actual value from values map. For example, string contains ${KAFKA_BROKERS} and values map: map["KAFKA_BROKERS"]="localhost:9092,localhost:9093" It then will be new StrOrArr with values StrOrArr{arrStr: [localhost:9092,localhost:9093]}

values key must only contain exact string similar like we define in Environment Variable on unix system. To define array, use comma separator between fields. To define array: * KAFKA_BROKERS=localhost:9092,localhost:9093 (simple, preferred) * KAFKA_BROKERS="localhost:9092","localhost:9093" (wrong example) the whole string "localhost:9092" will be treated as value, not localhost:9092

func String

func String(str string) *StrOrArr

func StringArray

func StringArray(arrStr []string) *StrOrArr

func (*StrOrArr) Array

func (s *StrOrArr) Array() []string

func (StrOrArr) Kind

func (s StrOrArr) Kind() Kind

func (StrOrArr) MarshalBSONValue

func (s StrOrArr) MarshalBSONValue() (bsontype.Type, []byte, error)

func (StrOrArr) MarshalJSON

func (s StrOrArr) MarshalJSON() ([]byte, error)

func (StrOrArr) MarshalYAML

func (s StrOrArr) MarshalYAML() (interface{}, error)

func (*StrOrArr) String

func (s *StrOrArr) String() string

func (*StrOrArr) UnmarshalBSONValue

func (s *StrOrArr) UnmarshalBSONValue(typ bsontype.Type, b []byte) error

func (*StrOrArr) UnmarshalJSON

func (s *StrOrArr) UnmarshalJSON(b []byte) error

func (*StrOrArr) UnmarshalYAML

func (s *StrOrArr) UnmarshalYAML(value *yaml.Node) error

Jump to

Keyboard shortcuts

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