Documentation ¶
Index ¶
- Variables
- func ArrayDeleteEmpties(s []string, keepSpaces bool) []string
- func Deref[T any](in *T) (result T)
- func FlatMergeMapStringInterface(base, changes map[string]interface{}) (result map[string]interface{}, err error)
- func GetAndUnsetEnv(key string) (result string, err error)
- func LookupEnvVar(key string) (value string)
- func ReadFile(file string) string
- func Ref[T any](in T) *T
- func RegisterValidators(validators []Validator, v *validator.Validate, trans ut.Translator)
- func RegisterValidatorsDefault(validators []Validator)
- func StringJoinWithoutEmpties(stringss []string, sep string, keepSpaces bool) string
- func StructToMapStringInterface(structt interface{}) (result map[string]interface{})
- func UnmarshalTestValue(t *testing.T, jsonInput string, value interface{})
- func UpcaseFirstStrict(s string) string
- type CanBeValidated
- type DeferFunc
- type Validator
- type ValidatorsCreatorFunc
Constants ¶
This section is empty.
Variables ¶
var ( // Translator provides a [ut.Translator] instance Translator ut.Translator // StructValidator provides a [validator.Validate] instance StructValidator *validator.Validate )
Functions ¶
func ArrayDeleteEmpties ¶
ArrayDeleteEmpties removes empty elements from a string array and returns a new array with the cleaned result.
Setting keepSpaces will not trim elements before checking for deletion
func Deref ¶
func Deref[T any](in *T) (result T)
Deref gives back the value of a provided pointer, even if in is nil
func FlatMergeMapStringInterface ¶
func FlatMergeMapStringInterface(base, changes map[string]interface{}) (result map[string]interface{}, err error)
FlatMergeMapStringInterface logically takes the base and merge changes onto it. Deletion is done by explicitly setting a field to its empty value. Nil is kept, so it could be set, explicitly. For more sophisticated merging, use a library like https://github.com/imdario/mergo
func GetAndUnsetEnv ¶
GetAndUnsetEnv is following the security pattern DeleteOnFirstUse when it comes to reading environment variables.
So the environment variable is read once and gets deleted
func LookupEnvVar ¶
LookupEnvVar returns the value of an environment variable if it exists, without caring about if the variable itself was defined or not.
func RegisterValidators ¶
func RegisterValidators(validators []Validator, v *validator.Validate, trans ut.Translator)
RegisterValidators helps to register [Validator]s with provided translations and validations
func RegisterValidatorsDefault ¶
func RegisterValidatorsDefault(validators []Validator)
RegisterValidatorsDefault allows registering validators and are held within this library
func StringJoinWithoutEmpties ¶
StringJoinWithoutEmpties joins elements of an array after deleting empty elements. For deleting empty array elements ArrayDeleteEmpties is used
func StructToMapStringInterface ¶
func StructToMapStringInterface(structt interface{}) (result map[string]interface{})
StructToMapStringInterface turns a given struct to a map[string]interface{}
func UnmarshalTestValue ¶
UnmarshalTestValue takes a jsonInput and a proper struct type as value and tries to unmarshal the JSON to the struct
func UpcaseFirstStrict ¶
UpcaseFirstStrict takes a string and only sets first letter to upcase
Types ¶
type CanBeValidated ¶
type CanBeValidated interface {
Validate() error
}
CanBeValidated describes a type that can be validated
type DeferFunc ¶
type DeferFunc func()
DeferFunc conveniently describes a type for a function that is intended to be used with a defer statement
func CreateTmpDir ¶
CreateTmpDir conveniently creates a temporary directory and returns the path to the temporary directory along with a function reference rmDir for directory removal.
In case of erros creating the temporary directory, err indicates an error
func OpenFileWrite ¶
OpenFileWrite opens a file determined by path for writing. The file gets created if it not exists
This function utilizes os.OpenFile providing `os.O_CREATE|os.O_WRONLY|os.O_TRUNC` and os.ModePerm as parameters
type ValidatorsCreatorFunc ¶
type ValidatorsCreatorFunc func(in CanBeValidated) []Validator
ValidatorsCreatorFunc describes a signature for functions that should be able to create [Validator]s