helper

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CsvStringOfTokensToMap

func CsvStringOfTokensToMap(log logger.Logger, s string) (map[string]string, error)

CsvStringOfTokensToMap expects a CSV of tokens "testA:testB, xyz1:abc2, ""j kh3: r st4"", ""j kh3:xyz"" and returns: m[testA]=testB m[xyz1]=abc2 m["j kh3"]=xyz It will take the last seen value for a given token.

func CsvToStringSliceTrimSpaces

func CsvToStringSliceTrimSpaces(s string) []string

Convert a string of the form, 'f1,f2,f3...' into a slice of string values. 1) Split on comma. 2) Remove leading and trailing spaces.

func CsvToStringSliceTrimSpaces2

func CsvToStringSliceTrimSpaces2(s string) (retval []string)

CsvToStringSliceTrimSpaces2 converts a string of the form, 'f1, f2, f3, ...' into a slice of string values.

func CsvToStringSliceTrimSpacesRemoveQuotes

func CsvToStringSliceTrimSpacesRemoveQuotes(s string) []string

Convert a string of the form, '"f1","f2","f3"...' into a slice of string values. 1) Split on comma. 2) Remove leading and trailing spaces. TODO: use proper CSV library to unwrap fields.

func EscapeQuotesInString

func EscapeQuotesInString(s string) string

EscapeQuotesInString will escape any quotes found in the strings with "\".

func GenerateSliceOfColsEqualCols

func GenerateSliceOfColsEqualCols(colList []string, srcAlias string, tgtAlias string) []string

func GenerateStringOfColsEqualsCols

func GenerateStringOfColsEqualsCols(colList []string, srcAlias string, tgtAlias string, separator string) string

Function to get a string "src.col1 = tgt.col1, src.col2 = tgt.col2" using the colList supplier and where the comma can be whatever separator you pass in.

func GetDsnEnvVarName

func GetDsnEnvVarName(connectionName string) string

func GetEnvVar

func GetEnvVar(k string, mandatory bool) (string, error)

GetEnvVar fetches OS environment variable. If the variable is not set it returns empty string. It also returns an error if there is a missing value AND mandatory == true.

func GetRegionEnvVarName

func GetRegionEnvVarName(connectionName string) string

func GetStringFromInterface

func GetStringFromInterface(log logger.Logger, input interface{}, useUTC bool) (retval string)

GetStringFromInterface will convert interface{} value to a string. Optionally return Times in UTC.

func GetStringFromInterfacePreserveTimeZone

func GetStringFromInterfacePreserveTimeZone(log logger.Logger, input interface{}) (retval string)

GetStringFromInterfacePreserveTimeZone will convert interface{} value to a string. Times will be in local time.

func GetStringFromInterfaceUseUtcTime

func GetStringFromInterfaceUseUtcTime(log logger.Logger, input interface{}) (retval string)

GetStringFromInterfacePreserveTimeZone will convert interface{} value to a string for the purposes of gt/lt comparison. Times will be converted to UTC for string comparison! TODO: remove logging from basic helper funcs

func GetStructErrorTxt4UnsetFields

func GetStructErrorTxt4UnsetFields(i interface{}, errTags *[]string)

getStructErrorTxt4UnsetFields will reflect over interface i and build a slice containing error text strings for any struct fields that are unset i.e. are the zero value for the given field type. The error text strings are fetched from the errorTxt tags values found in the supplied interface (struct) where tag mandatory:"yes" is set.

func GetTrueFalseStringAsBool

func GetTrueFalseStringAsBool(s string) bool

GetTrueFalseStringAsBool trims spaces from s and checks if it can regexp (case insensitive) match "true". It returns true if there's a match else false.

func InterfaceToString

func InterfaceToString(src []interface{}) []string

func OrderedMapToTokens

func OrderedMapToTokens(om *ordered_map.OrderedMap, trimQuotes bool) (string, error)

OrderedMapToTokens converts the supplied ordered map to a CSV of key:value,key:value,... All keys and values are expected to be of type string.

func OrderedMapValuesToStringSlice

func OrderedMapValuesToStringSlice(log logger.Logger, om *om.OrderedMap, l *[]string, idx *int)

Function to build a list of values found in ordered map 'om' supplied as input. Output - this function modifies the supplied list 'l' and 'idx' by reference.

func ReadValueFromEnv

func ReadValueFromEnv(name string, val *string) error

ReadValueFromEnv will convert name into an environment variable using EnvVarPrefix and the name converted to upper with dashes converted to underscores all separated by underscores. It will read the env var and populate the supplied val. If the env var is not set then return an error.

func ReadValueFromEnvWithDefault

func ReadValueFromEnvWithDefault(name string, defaultValue string) (v string)

ReadValueFromEnvWithDefault will read the value of name from the environment into v. If it's not set then it will apply the supplied defaultValue and return v.

func Split

func Split(s string, c string) (string, string)

Maybe s is of the form t c u. If so, return t, u. If not, return s, "".

func SplitRight

func SplitRight(s string, c string) (string, string)

func StringSliceToOrderedMap

func StringSliceToOrderedMap(s []string) *om.OrderedMap

StringSliceToOrderedMap adds each value in s to an ordered map with key and value set to the value in s.

func StringSliceToTokens

func StringSliceToTokens(log logger.Logger, s []string) (retval string)

SliceOfStringsToStringOfTokens converts slice { col1,col2 ,col3} to "col1:col1,col2:col2,col3:col3" Spaces are trimmed from the input.

func StringsToCsv

func StringsToCsv(s []string) string

StringsToCsv joins the strings by "," TODO: handle comma in a column name as this stuff is often turned into a CSV!

func StringsToCsv2

func StringsToCsv2(log logger.Logger, s []string) string

func ToUpperIfNotQuoted

func ToUpperIfNotQuoted(s []string) []string

ToUpperIfNotQuoted converts any non-quoted strings to upper case.

func ToUpperQuotedIfNotQuoted

func ToUpperQuotedIfNotQuoted(s []string) []string

ToUpperQuotedIfNotQuoted converts any non-quoted strings to upper case and quotes them.

func TokensToOrderedMap

func TokensToOrderedMap(s string) *ordered_map.OrderedMap

Convert a string of the form, 'k1:v1,k2:v2' into an ordered map and return a pointer to it. 1) Split on comma to find each key:value pair. 2) Split on colon to separate the key from the value.

func ValidateStructIsPopulated

func ValidateStructIsPopulated(cfg interface{}) (err error)

validateStructIsPopulated will check if any mandatory fields in cfg are missing. It uses struct tags to determine which fields are mandatory and the error text to fetch. The error text returned is just a list of the struct tags with key "errorTxt".

Types

type AtomBool

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

func (*AtomBool) Get

func (b *AtomBool) Get() bool

func (*AtomBool) Set

func (b *AtomBool) Set(value bool)

Jump to

Keyboard shortcuts

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