ease

package
v1.5.51 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Translator provides a [ut.Translator] instance
	Translator ut.Translator
	// StructValidator provides a [validator.Validate] instance
	StructValidator *validator.Validate
)

Functions

func ArrayDeleteEmpties

func ArrayDeleteEmpties(s []string, keepSpaces bool) []string

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

func GetAndUnsetEnv(key string) (result string, err error)

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

func LookupEnvVar(key string) (value string)

LookupEnvVar returns the value of an environment variable if it exists, without caring about if the variable itself was defined or not.

func ReadFile

func ReadFile(file string) string

ReadFile reads a file by name and returns its content as string

func Ref

func Ref[T any](in T) *T

Ref obtains a pointer to the provided value

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

func StringJoinWithoutEmpties(stringss []string, sep string, keepSpaces bool) string

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

func UnmarshalTestValue(t *testing.T, jsonInput string, value interface{})

UnmarshalTestValue takes a jsonInput and a proper struct type as value and tries to unmarshal the JSON to the struct

func UpcaseFirstStrict

func UpcaseFirstStrict(s string) string

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

func CreateTmpDir(dirName string) (tmpDir string, rmDir DeferFunc, err error)

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

func OpenFileWrite(filepath string) (*os.File, DeferFunc, error)

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 Validator

type Validator struct {
	Field     string
	Message   string
	Validator func(fl validator.FieldLevel) bool
}

Validator encapsulates information about how to validate a certain struct field

type ValidatorsCreatorFunc

type ValidatorsCreatorFunc func(in CanBeValidated) []Validator

ValidatorsCreatorFunc describes a signature for functions that should be able to create [Validator]s

Jump to

Keyboard shortcuts

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